rdbms: Rename "memCache" to "memStash" in LBFactory
[mediawiki.git] / tests / phpunit / includes / externalstore / ExternalStoreTest.php
bloba365c4de2e5409bcbf70ba67d1b7853b206b7d89
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', [ '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 = [
50 'cluster1' => [
51 '200' => 'Hello',
52 '300' => [
53 'Hello', 'World',
58 /**
59 * Fetch data from given URL
60 * @param string $url 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
79 && is_array( $this->data[$cluster][$id] )
80 && isset( $this->data[$cluster][$id][$itemID] )
81 ) {
82 return $this->data[$cluster][$id][$itemID];
85 return $this->data[$cluster][$id];