Release notes for Iabf4873f
[mediawiki.git] / tests / phpunit / includes / ExternalStoreTest.php
blobba155a48e856b6e1daef73954ecb99bb812dd2f9
1 <?php
2 /**
3 * External Store tests
4 */
6 class ExternalStoreTest extends MediaWikiTestCase {
8 /**
9 * @covers ExternalStore::fetchFromURL
11 public function testExternalFetchFromURL() {
12 $this->setMwGlobals( 'wgExternalStores', false );
14 $this->assertFalse(
15 ExternalStore::fetchFromURL( 'FOO://cluster1/200' ),
16 'Deny if wgExternalStores is not set to a non-empty array'
19 $this->setMwGlobals( 'wgExternalStores', array( 'FOO' ) );
21 $this->assertEquals(
22 ExternalStore::fetchFromURL( 'FOO://cluster1/200' ),
23 'Hello',
24 'Allow FOO://cluster1/200'
26 $this->assertEquals(
27 ExternalStore::fetchFromURL( 'FOO://cluster1/300/0' ),
28 'Hello',
29 'Allow FOO://cluster1/300/0'
31 # Assertions for r68900
32 $this->assertFalse(
33 ExternalStore::fetchFromURL( 'ftp.example.org' ),
34 'Deny domain ftp.example.org'
36 $this->assertFalse(
37 ExternalStore::fetchFromURL( '/example.txt' ),
38 'Deny path /example.txt'
40 $this->assertFalse(
41 ExternalStore::fetchFromURL( 'http://' ),
42 'Deny protocol http://'
47 class ExternalStoreFOO {
49 protected $data = array(
50 'cluster1' => array(
51 '200' => 'Hello',
52 '300' => array(
53 'Hello', 'World',
58 /**
59 * Fetch data from given URL
60 * @param $url String: an url of the form FOO://cluster/id or FOO://cluster/id/itemid.
61 * @return mixed
63 function fetchFromURL( $url ) {
64 // Based on ExternalStoreDB
65 $path = explode( '/', $url );
66 $cluster = $path[2];
67 $id = $path[3];
68 if ( isset( $path[4] ) ) {
69 $itemID = $path[4];
70 } else {
71 $itemID = false;
74 if ( !isset( $this->data[$cluster][$id] ) ) {
75 return null;
78 if ( $itemID !== false && is_array( $this->data[$cluster][$id] ) && isset( $this->data[$cluster][$id][$itemID] ) ) {
79 return $this->data[$cluster][$id][$itemID];
82 return $this->data[$cluster][$id];