Make "/*@noflip*/ /*@embed*/" annotation work without CSSJanus hacks
[lhc/web/wiklou.git] / tests / phpunit / includes / resourceloader / ResourceLoaderTest.php
index d72c5e7..7664d5b 100644 (file)
@@ -90,6 +90,15 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
                $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.
@@ -108,14 +117,16 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
                $contextLtr = self::getResourceLoaderContext( 'en' );
                $contextRtl = self::getResourceLoaderContext( 'he' );
 
+               // 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"
                );
        }
@@ -161,6 +172,43 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
                );
        }
 
+       public static function provideAddSource() {
+               return array(
+                       array( 'examplewiki', '//example.org/w/load.php', 'examplewiki' ),
+                       array( 'example2wiki', array( 'loadScript' => '//example.com/w/load.php' ), 'example2wiki' ),
+                       array(
+                               array( 'foowiki' => '//foo.org/w/load.php', 'bazwiki' => '//baz.org/w/load.php' ),
+                               null,
+                               array( 'foowiki', 'bazwiki' )
+                       ),
+                       array(
+                               array( 'foowiki' => '//foo.org/w/load.php' ),
+                               null,
+                               false,
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideAddSource
+        * @covers ResourceLoader::addSource
+        */
+       public function testAddSource( $name, $info, $expected ) {
+               $rl = new ResourceLoader;
+               if ( $expected === false ) {
+                       $this->setExpectedException( 'MWException', 'ResourceLoader duplicate source addition error' );
+                       $rl->addSource( $name, $info );
+               }
+               $rl->addSource( $name, $info );
+               if ( is_array( $expected ) ) {
+                       foreach ( $expected as $source ) {
+                               $this->assertArrayHasKey( $source, $rl->getSources() );
+                       }
+               } else {
+                       $this->assertArrayHasKey( $expected, $rl->getSources() );
+               }
+       }
+
        public static function fakeSources() {
                return array(
                        'examplewiki' => array(