test: coverage recording now needs to be explicit
[mediawiki.git] / tests / phpunit / includes / ExternalStoreTest.php
blob99544e7ed0fa7534e54f56ea133554f08649d776
1 <?php
2 /**
3 * External Store tests
4 */
6 class ExternalStoreTest extends MediaWikiTestCase {
8 function testExternalFetchFromURL() {
9 $this->setMwGlobals( 'wgExternalStores', false );
11 $this->assertFalse(
12 ExternalStore::fetchFromURL( 'FOO://cluster1/200' ),
13 'Deny if wgExternalStores is not set to a non-empty array'
16 $this->setMwGlobals( 'wgExternalStores', array( 'FOO' ) );
18 $this->assertEquals(
19 ExternalStore::fetchFromURL( 'FOO://cluster1/200' ),
20 'Hello',
21 'Allow FOO://cluster1/200'
23 $this->assertEquals(
24 ExternalStore::fetchFromURL( 'FOO://cluster1/300/0' ),
25 'Hello',
26 'Allow FOO://cluster1/300/0'
28 # Assertions for r68900
29 $this->assertFalse(
30 ExternalStore::fetchFromURL( 'ftp.example.org' ),
31 'Deny domain ftp.example.org'
33 $this->assertFalse(
34 ExternalStore::fetchFromURL( '/example.txt' ),
35 'Deny path /example.txt'
37 $this->assertFalse(
38 ExternalStore::fetchFromURL( 'http://' ),
39 'Deny protocol http://'
44 class ExternalStoreFOO {
46 protected $data = array(
47 'cluster1' => array(
48 '200' => 'Hello',
49 '300' => array(
50 'Hello', 'World',
55 /**
56 * Fetch data from given URL
57 * @param $url String: an url of the form FOO://cluster/id or FOO://cluster/id/itemid.
58 * @return mixed
60 function fetchFromURL( $url ) {
61 // Based on ExternalStoreDB
62 $path = explode( '/', $url );
63 $cluster = $path[2];
64 $id = $path[3];
65 if ( isset( $path[4] ) ) {
66 $itemID = $path[4];
67 } else {
68 $itemID = false;
71 if ( !isset( $this->data[$cluster][$id] ) ) {
72 return null;
75 if ( $itemID !== false && is_array( $this->data[$cluster][$id] ) && isset( $this->data[$cluster][$id][$itemID] ) ) {
76 return $this->data[$cluster][$id][$itemID];
79 return $this->data[$cluster][$id];