MediaWiki  REL1_24
ExternalStoreTest.php
Go to the documentation of this file.
00001 <?php
00006 class ExternalStoreTest extends MediaWikiTestCase {
00007 
00011     public function testExternalFetchFromURL() {
00012         $this->setMwGlobals( 'wgExternalStores', false );
00013 
00014         $this->assertFalse(
00015             ExternalStore::fetchFromURL( 'FOO://cluster1/200' ),
00016             'Deny if wgExternalStores is not set to a non-empty array'
00017         );
00018 
00019         $this->setMwGlobals( 'wgExternalStores', array( 'FOO' ) );
00020 
00021         $this->assertEquals(
00022             ExternalStore::fetchFromURL( 'FOO://cluster1/200' ),
00023             'Hello',
00024             'Allow FOO://cluster1/200'
00025         );
00026         $this->assertEquals(
00027             ExternalStore::fetchFromURL( 'FOO://cluster1/300/0' ),
00028             'Hello',
00029             'Allow FOO://cluster1/300/0'
00030         );
00031         # Assertions for r68900
00032         $this->assertFalse(
00033             ExternalStore::fetchFromURL( 'ftp.example.org' ),
00034             'Deny domain ftp.example.org'
00035         );
00036         $this->assertFalse(
00037             ExternalStore::fetchFromURL( '/example.txt' ),
00038             'Deny path /example.txt'
00039         );
00040         $this->assertFalse(
00041             ExternalStore::fetchFromURL( 'http://' ),
00042             'Deny protocol http://'
00043         );
00044     }
00045 }
00046 
00047 class ExternalStoreFOO {
00048 
00049     protected $data = array(
00050         'cluster1' => array(
00051             '200' => 'Hello',
00052             '300' => array(
00053                 'Hello', 'World',
00054             ),
00055         ),
00056     );
00057 
00063     function fetchFromURL( $url ) {
00064         // Based on ExternalStoreDB
00065         $path = explode( '/', $url );
00066         $cluster = $path[2];
00067         $id = $path[3];
00068         if ( isset( $path[4] ) ) {
00069             $itemID = $path[4];
00070         } else {
00071             $itemID = false;
00072         }
00073 
00074         if ( !isset( $this->data[$cluster][$id] ) ) {
00075             return null;
00076         }
00077 
00078         if ( $itemID !== false
00079             && is_array( $this->data[$cluster][$id] )
00080             && isset( $this->data[$cluster][$id][$itemID] )
00081         ) {
00082             return $this->data[$cluster][$id][$itemID];
00083         }
00084 
00085         return $this->data[$cluster][$id];
00086     }
00087 }