X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fregistration%2FExtensionRegistryTest.php;h=7120a91a9738f769c8b811211222abd59ac62018;hb=138298b397b308ad6e4bfc7088884d90e8ac1e37;hp=a6f69b64d92c24cfc44eb3c11746a717c5b9124a;hpb=e69bcfad17d67da5113cdd75276a5f7b5cefb123;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/registration/ExtensionRegistryTest.php b/tests/phpunit/includes/registration/ExtensionRegistryTest.php index a6f69b64d9..7120a91a97 100644 --- a/tests/phpunit/includes/registration/ExtensionRegistryTest.php +++ b/tests/phpunit/includes/registration/ExtensionRegistryTest.php @@ -1,9 +1,88 @@ dataDir = __DIR__ . '/../../data/registration'; + } + + public function testQueue_invalid() { + $registry = new ExtensionRegistry(); + $path = __DIR__ . '/doesnotexist.json'; + $this->setExpectedException( + Exception::class, + "$path does not exist!" + ); + $registry->queue( $path ); + } + + public function testQueue() { + $registry = new ExtensionRegistry(); + $path = "{$this->dataDir}/good.json"; + $registry->queue( $path ); + $this->assertArrayHasKey( + $path, + $registry->getQueue() + ); + $registry->clearQueue(); + $this->assertEmpty( $registry->getQueue() ); + } + + public function testLoadFromQueue_empty() { + $registry = new ExtensionRegistry(); + $registry->loadFromQueue(); + $this->assertEmpty( $registry->getAllThings() ); + } + + public function testLoadFromQueue_late() { + $registry = new ExtensionRegistry(); + $registry->finish(); + $registry->queue( "{$this->dataDir}/good.json" ); + $this->setExpectedException( + MWException::class, + "The following paths tried to load late: {$this->dataDir}/good.json" + ); + $registry->loadFromQueue(); + } + + public function testLoadFromQueue() { + $registry = new ExtensionRegistry(); + $registry->queue( "{$this->dataDir}/good.json" ); + $registry->loadFromQueue(); + $this->assertArrayHasKey( 'FooBar', $registry->getAllThings() ); + $this->assertTrue( $registry->isLoaded( 'FooBar' ) ); + $this->assertSame( [ 'test' ], $registry->getAttribute( 'FooBarAttr' ) ); + $this->assertSame( [], $registry->getAttribute( 'NotLoadedAttr' ) ); + } + + /** + * @expectedException PHPUnit_Framework_Error + */ + public function testReadFromQueue_nonexistent() { + $registry = new ExtensionRegistry(); + $registry->readFromQueue( [ + __DIR__ . '/doesnotexist.json' => 1 + ] ); + } + + public function testReadFromQueueInitializeAutoloaderWithPsr4Namespaces() { + $registry = new ExtensionRegistry(); + $registry->readFromQueue( [ + "{$this->dataDir}/autoload_namespaces.json" => 1 + ] ); + $this->assertTrue( + class_exists( 'Test\\MediaWiki\\AutoLoader\\TestFooBar' ), + "Registry initializes Autoloader from AutoloadNamespaces" + ); + } + /** - * @covers ExtensionRegistry::exportExtractedData * @dataProvider provideExportExtractedDataGlobals */ public function testExportExtractedDataGlobals( $desc, $before, $globals, $expected ) {