wiki.techinc.nl/tests/phpunit/includes/ExternalStoreTest.php
umherirrender 092cd8ee31 Fixed some @params documentation (tests)
Swapped some "$var type" to "type $var" or added missing types
before the $var. Changed some other types to match the more common
spelling. Makes beginning of some text in captial.
Also added some missing @param.

Change-Id: Ic8aaf0a93796b97d0fa4617c1f86ff59f4b36131
2014-04-17 20:43:42 +02:00

84 lines
1.8 KiB
PHP

<?php
/**
* External Store tests
*/
class ExternalStoreTest extends MediaWikiTestCase {
/**
* @covers ExternalStore::fetchFromURL
*/
public function testExternalFetchFromURL() {
$this->setMwGlobals( 'wgExternalStores', false );
$this->assertFalse(
ExternalStore::fetchFromURL( 'FOO://cluster1/200' ),
'Deny if wgExternalStores is not set to a non-empty array'
);
$this->setMwGlobals( 'wgExternalStores', array( 'FOO' ) );
$this->assertEquals(
ExternalStore::fetchFromURL( 'FOO://cluster1/200' ),
'Hello',
'Allow FOO://cluster1/200'
);
$this->assertEquals(
ExternalStore::fetchFromURL( 'FOO://cluster1/300/0' ),
'Hello',
'Allow FOO://cluster1/300/0'
);
# Assertions for r68900
$this->assertFalse(
ExternalStore::fetchFromURL( 'ftp.example.org' ),
'Deny domain ftp.example.org'
);
$this->assertFalse(
ExternalStore::fetchFromURL( '/example.txt' ),
'Deny path /example.txt'
);
$this->assertFalse(
ExternalStore::fetchFromURL( 'http://' ),
'Deny protocol http://'
);
}
}
class ExternalStoreFOO {
protected $data = array(
'cluster1' => array(
'200' => 'Hello',
'300' => array(
'Hello', 'World',
),
),
);
/**
* Fetch data from given URL
* @param string $url An url of the form FOO://cluster/id or FOO://cluster/id/itemid.
* @return mixed
*/
function fetchFromURL( $url ) {
// Based on ExternalStoreDB
$path = explode( '/', $url );
$cluster = $path[2];
$id = $path[3];
if ( isset( $path[4] ) ) {
$itemID = $path[4];
} else {
$itemID = false;
}
if ( !isset( $this->data[$cluster][$id] ) ) {
return null;
}
if ( $itemID !== false && is_array( $this->data[$cluster][$id] ) && isset( $this->data[$cluster][$id][$itemID] ) ) {
return $this->data[$cluster][$id][$itemID];
}
return $this->data[$cluster][$id];
}
}