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