X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fresourceloader%2FMessageBlobStoreTest.php;h=628ddb1ba1f1dff0c1871980477e7424a3b0f2bf;hb=34bd6f0b6bd0f0af03b448deddb85cdea358e0fb;hp=9afa232bd47207e99fe137d8bc3e54c8e167bd72;hpb=31e768e643bd513daa3e8b9720c2f3944ac7092c;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/resourceloader/MessageBlobStoreTest.php b/tests/phpunit/includes/resourceloader/MessageBlobStoreTest.php index 9afa232bd4..628ddb1ba1 100644 --- a/tests/phpunit/includes/resourceloader/MessageBlobStoreTest.php +++ b/tests/phpunit/includes/resourceloader/MessageBlobStoreTest.php @@ -11,6 +11,8 @@ class MessageBlobStoreTest extends PHPUnit\Framework\TestCase { use MediaWikiCoversValidator; use PHPUnit4And6Compat; + const NAME = 'test.blobstore'; + protected function setUp() { parent::setUp(); // MediaWiki's test wrapper sets $wgMainWANCache to CACHE_NONE. @@ -24,20 +26,22 @@ class MessageBlobStoreTest extends PHPUnit\Framework\TestCase { } public function testBlobCreation() { - $module = $this->makeModule( [ 'mainpage' ] ); - $rl = new ResourceLoader(); - $rl->register( $module->getName(), $module ); + $rl = new EmptyResourceLoader(); + $rl->register( self::NAME, [ + 'factory' => function () { + return $this->makeModule( [ 'mainpage' ] ); + } + ] ); $blobStore = $this->makeBlobStore( null, $rl ); - $blob = $blobStore->getBlob( $module, 'en' ); + $blob = $blobStore->getBlob( $rl->getModule( self::NAME ), 'en' ); $this->assertEquals( '{"mainpage":"Main Page"}', $blob, 'Generated blob' ); } public function testBlobCreation_empty() { $module = $this->makeModule( [] ); - $rl = new ResourceLoader(); - $rl->register( $module->getName(), $module ); + $rl = new EmptyResourceLoader(); $blobStore = $this->makeBlobStore( null, $rl ); $blob = $blobStore->getBlob( $module, 'en' ); @@ -47,8 +51,7 @@ class MessageBlobStoreTest extends PHPUnit\Framework\TestCase { public function testBlobCreation_unknownMessage() { $module = $this->makeModule( [ 'i-dont-exist', 'mainpage', 'i-dont-exist2' ] ); - $rl = new ResourceLoader(); - $rl->register( $module->getName(), $module ); + $rl = new EmptyResourceLoader(); $blobStore = $this->makeBlobStore( null, $rl ); // Generating a blob should continue without errors, @@ -58,9 +61,15 @@ class MessageBlobStoreTest extends PHPUnit\Framework\TestCase { } public function testMessageCachingAndPurging() { - $module = $this->makeModule( [ 'example' ] ); - $rl = new ResourceLoader(); - $rl->register( $module->getName(), $module ); + $rl = new EmptyResourceLoader(); + // Register it so that MessageBlobStore::updateMessage can + // discover it from the registry as a module that uses this message. + $rl->register( self::NAME, [ + 'factory' => function () { + return $this->makeModule( [ 'example' ] ); + } + ] ); + $module = $rl->getModule( self::NAME ); $blobStore = $this->makeBlobStore( [ 'fetchMessage' ], $rl ); // Advance this new WANObjectCache instance to a normal state, @@ -104,8 +113,7 @@ class MessageBlobStoreTest extends PHPUnit\Framework\TestCase { public function testPurgeEverything() { $module = $this->makeModule( [ 'example' ] ); - $rl = new ResourceLoader(); - $rl->register( $module->getName(), $module ); + $rl = new EmptyResourceLoader(); $blobStore = $this->makeBlobStore( [ 'fetchMessage' ], $rl ); // Advance this new WANObjectCache instance to a normal state. $blobStore->getBlob( $module, 'en' ); @@ -138,8 +146,7 @@ class MessageBlobStoreTest extends PHPUnit\Framework\TestCase { public function testValidateAgainstModuleRegistry() { // Arrange version 1 of a module $module = $this->makeModule( [ 'foo' ] ); - $rl = new ResourceLoader(); - $rl->register( $module->getName(), $module ); + $rl = new EmptyResourceLoader(); $blobStore = $this->makeBlobStore( [ 'fetchMessage' ], $rl ); $blobStore->expects( $this->once() ) ->method( 'fetchMessage' ) @@ -157,8 +164,7 @@ class MessageBlobStoreTest extends PHPUnit\Framework\TestCase { // must always match the set of message keys required by the module. // We do not receive purges for this because no messages were changed. $module = $this->makeModule( [ 'foo', 'bar' ] ); - $rl = new ResourceLoader(); - $rl->register( $module->getName(), $module ); + $rl = new EmptyResourceLoader(); $blobStore = $this->makeBlobStore( [ 'fetchMessage' ], $rl ); $blobStore->expects( $this->exactly( 2 ) ) ->method( 'fetchMessage' ) @@ -191,7 +197,7 @@ class MessageBlobStoreTest extends PHPUnit\Framework\TestCase { private function makeModule( array $messages ) { $module = new ResourceLoaderTestModule( [ 'messages' => $messages ] ); - $module->setName( 'test.blobstore' ); + $module->setName( self::NAME ); return $module; } }