Fix SpecialPageFactory list handling
[lhc/web/wiklou.git] / tests / phpunit / includes / specialpage / SpecialPageFactoryTest.php
index 4619c2e..cb12273 100644 (file)
@@ -28,6 +28,25 @@ class SpecialPageFactoryTest extends MediaWikiTestCase {
                SpecialPageFactory::resetList();
        }
 
+       public function testResetList() {
+               SpecialPageFactory::resetList();
+               $this->assertContains( 'Specialpages', SpecialPageFactory::getNames() );
+       }
+
+       public function testHookNotCalledTwice() {
+               $count = 0;
+               $this->mergeMwGlobalArrayValue( 'wgHooks', array(
+                       'SpecialPage_initList' => array(
+                               function () use ( &$count ) {
+                                       $count++;
+                               }
+               ) ) );
+               SpecialPageFactory::resetList();
+               SpecialPageFactory::getNames();
+               SpecialPageFactory::getNames();
+               $this->assertEquals( 1, $count );
+       }
+
        public function newSpecialAllPages() {
                return new SpecialAllPages();
        }
@@ -35,10 +54,10 @@ class SpecialPageFactoryTest extends MediaWikiTestCase {
        public function specialPageProvider() {
                return array(
                        'class name' => array( 'SpecialAllPages', false ),
-                       'closure' => array( function() {
+                       'closure' => array( function () {
                                return new SpecialAllPages();
                        }, false ),
-                       'function' => array( array( $this, 'newSpecialAllPages' ), false  ),
+                       'function' => array( array( $this, 'newSpecialAllPages' ), false ),
                );
        }
 
@@ -235,4 +254,19 @@ class SpecialPageFactoryTest extends MediaWikiTestCase {
                );
        }
 
+       public function testGetAliasListRecursion() {
+               $called = false;
+               $this->mergeMwGlobalArrayValue( 'wgHooks', array(
+                       'SpecialPage_initList' => array(
+                               function () use ( &$called ) {
+                                       SpecialPageFactory::getLocalNameFor( 'Specialpages' );
+                                       $called = true;
+                               }
+                       ),
+               ) );
+               SpecialPageFactory::resetList();
+               SpecialPageFactory::getLocalNameFor( 'Specialpages' );
+               $this->assertTrue( $called, 'Recursive call succeeded' );
+       }
+
 }