Merge "Improve ExtensionRegistry test coverage"
[lhc/web/wiklou.git] / tests / phpunit / includes / registration / ExtensionRegistryTest.php
index 1de4265..67bc088 100644 (file)
@@ -1,9 +1,57 @@
 <?php
 
+/**
+ * @covers ExtensionRegistry
+ */
 class ExtensionRegistryTest extends MediaWikiTestCase {
 
+       private $dataDir;
+
+       public function setUp() {
+               parent::setUp();
+               $this->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();
+       }
+
        /**
-        * @covers ExtensionRegistry::exportExtractedData
         * @dataProvider provideExportExtractedDataGlobals
         */
        public function testExportExtractedDataGlobals( $desc, $before, $globals, $expected ) {
@@ -28,7 +76,7 @@ class ExtensionRegistryTest extends MediaWikiTestCase {
                        'autoloaderPaths' => []
                ];
                $registry = new ExtensionRegistry();
-               $class = new ReflectionClass( 'ExtensionRegistry' );
+               $class = new ReflectionClass( ExtensionRegistry::class );
                $method = $class->getMethod( 'exportExtractedData' );
                $method->setAccessible( true );
                $method->invokeArgs( $registry, [ $info ] );
@@ -259,7 +307,7 @@ class ExtensionRegistryTest extends MediaWikiTestCase {
                                                'JsonZeroConfig' => [
                                                        'namespace' => 480,
                                                        'nsName' => 'Zero',
-                                                       'isLocal' => false,
+                                                       'isLocal' => true,
                                                ],
                                        ],
                                ],
@@ -287,6 +335,18 @@ class ExtensionRegistryTest extends MediaWikiTestCase {
                                        ],
                                ],
                        ],
+                       [
+                               'global is null before',
+                               [
+                                       'NullGlobal' => null,
+                               ],
+                               [
+                                       'NullGlobal' => 'not-null'
+                               ],
+                               [
+                                       'NullGlobal' => null
+                               ],
+                       ],
                ];
        }
 }