Merge "mw.ui: button: Update focus state"
[lhc/web/wiklou.git] / tests / phpunit / includes / resourceloader / ResourceLoaderTest.php
index d2e118c..5d83239 100644 (file)
@@ -2,8 +2,6 @@
 
 class ResourceLoaderTest extends ResourceLoaderTestCase {
 
-       protected static $resourceLoaderRegisterModulesHook;
-
        protected function setUp() {
                parent::setUp();
 
@@ -30,17 +28,6 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
                ) );
        }
 
-       /* Hook Methods */
-
-       /**
-        * ResourceLoaderRegisterModules hook
-        */
-       public static function resourceLoaderRegisterModules( &$resourceLoader ) {
-               self::$resourceLoaderRegisterModulesHook = true;
-
-               return true;
-       }
-
        /* Provider Methods */
        public static function provideValidModules() {
                return array(
@@ -56,9 +43,21 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
         * @covers ResourceLoader::__construct
         */
        public function testCreatingNewResourceLoaderCallsRegistrationHook() {
-               self::$resourceLoaderRegisterModulesHook = false;
+               $resourceLoaderRegisterModulesHook = false;
+
+               $this->setMwGlobals( 'wgHooks', array(
+                       'ResourceLoaderRegisterModules' => array(
+                               function ( &$resourceLoader ) use ( &$resourceLoaderRegisterModulesHook ) {
+                                       $resourceLoaderRegisterModulesHook = true;
+                               }
+                       )
+               ) );
+
                $resourceLoader = new ResourceLoader();
-               $this->assertTrue( self::$resourceLoaderRegisterModulesHook );
+               $this->assertTrue(
+                       $resourceLoaderRegisterModulesHook,
+                       'Hook ResourceLoaderRegisterModules called'
+               );
 
                return $resourceLoader;
        }
@@ -80,16 +79,26 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
         * @covers ResourceLoaderFileModule::compileLessFile
         */
        public function testLessFileCompilation() {
-               $context = self::getResourceLoaderContext();
+               $context = $this->getResourceLoaderContext();
                $basePath = __DIR__ . '/../../data/less/module';
                $module = new ResourceLoaderFileModule( array(
                        'localBasePath' => $basePath,
                        'styles' => array( 'styles.less' ),
                ) );
+               $module->setName( 'test.less' );
                $styles = $module->getStyles( $context );
                $this->assertStringEqualsFile( $basePath . '/styles.css', $styles['all'] );
        }
 
+       /**
+        * Strip @noflip annotations from CSS code.
+        * @param string $css
+        * @return string
+        */
+       private function stripNoflip( $css ) {
+               return str_replace( '/*@noflip*/ ', '', $css );
+       }
+
        /**
         * What happens when you mix @embed and @noflip?
         * This really is an integration test, but oh well.
@@ -105,17 +114,19 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
                        'styles' => array( 'expected.css' ),
                ) );
 
-               $contextLtr = self::getResourceLoaderContext( 'en' );
-               $contextRtl = self::getResourceLoaderContext( 'he' );
+               $contextLtr = $this->getResourceLoaderContext( 'en', 'ltr' );
+               $contextRtl = $this->getResourceLoaderContext( 'he', 'rtl' );
 
+               // Since we want to compare the effect of @noflip+@embed against the effect of just @embed, and
+               // the @noflip annotations are always preserved, we need to strip them first.
                $this->assertEquals(
                        $expectedModule->getStyles( $contextLtr ),
-                       $testModule->getStyles( $contextLtr ),
+                       $this->stripNoflip( $testModule->getStyles( $contextLtr ) ),
                        "/*@noflip*/ with /*@embed*/ gives correct results in LTR mode"
                );
                $this->assertEquals(
                        $expectedModule->getStyles( $contextLtr ),
-                       $testModule->getStyles( $contextRtl ),
+                       $this->stripNoflip( $testModule->getStyles( $contextRtl ) ),
                        "/*@noflip*/ with /*@embed*/ gives correct results in RTL mode"
                );
        }
@@ -231,7 +242,3 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
                }
        }
 }
-
-/* Hooks */
-global $wgHooks;
-$wgHooks['ResourceLoaderRegisterModules'][] = 'ResourceLoaderTest::resourceLoaderRegisterModules';