X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fexternalstore%2FExternalStoreTest.php;h=60db27da3742300f69c6f3ed5eab23a4cfcfa53b;hp=a365c4de2e5409bcbf70ba67d1b7853b206b7d89;hb=6cfb2e3d7a2b96d5041312fcec88248bb46573d7;hpb=b5906606e1aa1a795231fb813b766818b1dd6c25 diff --git a/tests/phpunit/includes/externalstore/ExternalStoreTest.php b/tests/phpunit/includes/externalstore/ExternalStoreTest.php index a365c4de2e..60db27da37 100644 --- a/tests/phpunit/includes/externalstore/ExternalStoreTest.php +++ b/tests/phpunit/includes/externalstore/ExternalStoreTest.php @@ -1,31 +1,39 @@ setMwGlobals( 'wgExternalStores', false ); + public function testExternalFetchFromURL_noExternalStores() { + $this->setService( + 'ExternalStoreFactory', + new ExternalStoreFactory( [], [], 'test-id' ) + ); $this->assertFalse( - ExternalStore::fetchFromURL( 'FOO://cluster1/200' ), + ExternalStore::fetchFromURL( 'ForTesting://cluster1/200' ), 'Deny if wgExternalStores is not set to a non-empty array' ); + } - $this->setMwGlobals( 'wgExternalStores', [ 'FOO' ] ); + /** + * @covers ExternalStore::fetchFromURL + */ + public function testExternalFetchFromURL_someExternalStore() { + $this->setService( + 'ExternalStoreFactory', + new ExternalStoreFactory( [ 'ForTesting' ], [ 'ForTesting://cluster1' ], 'test-id' ) + ); $this->assertEquals( - ExternalStore::fetchFromURL( 'FOO://cluster1/200' ), 'Hello', + ExternalStore::fetchFromURL( 'ForTesting://cluster1/200' ), 'Allow FOO://cluster1/200' ); $this->assertEquals( - ExternalStore::fetchFromURL( 'FOO://cluster1/300/0' ), 'Hello', + ExternalStore::fetchFromURL( 'ForTesting://cluster1/300/0' ), 'Allow FOO://cluster1/300/0' ); # Assertions for r68900 @@ -43,45 +51,3 @@ class ExternalStoreTest extends MediaWikiTestCase { ); } } - -class ExternalStoreFOO { - - protected $data = [ - 'cluster1' => [ - '200' => 'Hello', - '300' => [ - '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]; - } -}