Add a test for mixed /*@noflip*/ and /*@embed*/ CSS annotations
authorBartosz Dziewoński <matma.rex@gmail.com>
Mon, 18 Aug 2014 12:56:18 +0000 (14:56 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Mon, 18 Aug 2014 14:40:25 +0000 (16:40 +0200)
Given that we have entirely separate code for handling one and the
other, and given the nature of code comments stuffed inside other
structures, this isn't really obvious that they work.

And indeed, "/*@noflip*/ /*@embed*/" doesn't work (filed bug 69698).
Amazingly, all other combinations do.

Change-Id: Ie30bab251eb4abee122c783d057de4102e53d1fc

tests/phpunit/ResourceLoaderTestCase.php
tests/phpunit/data/css/expected.css [new file with mode: 0644]
tests/phpunit/data/css/simple-ltr.gif [new file with mode: 0644]
tests/phpunit/data/css/simple-rtl.gif [new file with mode: 0644]
tests/phpunit/data/css/test.css [new file with mode: 0644]
tests/phpunit/includes/resourceloader/ResourceLoaderTest.php

index f316f56..96eedb4 100644 (file)
@@ -1,10 +1,10 @@
 <?php
 
 abstract class ResourceLoaderTestCase extends MediaWikiTestCase {
-       protected static function getResourceLoaderContext() {
+       protected static function getResourceLoaderContext( $lang = 'en' ) {
                $resourceLoader = new ResourceLoader();
                $request = new FauxRequest( array(
-                               'lang' => 'en',
+                               'lang' => $lang,
                                'modules' => 'startup',
                                'only' => 'scripts',
                                'skin' => 'vector',
diff --git a/tests/phpunit/data/css/expected.css b/tests/phpunit/data/css/expected.css
new file mode 100644 (file)
index 0000000..74eb21e
--- /dev/null
@@ -0,0 +1,12 @@
+/* All of the combinations should result in the same output in LTR and RTL mode. */
+
+.selector { /*@embed*/ background-image: url(simple-ltr.gif); }
+
+.selector { /*@embed*/ background-image: url(simple-ltr.gif); }
+
+/* Doesn't work! */
+/*.selector { /*@noflip* / /*@embed* / background-image: url(simple-ltr.gif); }*/
+
+.selector { /*@embed*/ background-image: url(simple-ltr.gif); }
+
+.selector { /*@embed*/ background-image: url(simple-ltr.gif); }
diff --git a/tests/phpunit/data/css/simple-ltr.gif b/tests/phpunit/data/css/simple-ltr.gif
new file mode 100644 (file)
index 0000000..13c43e9
Binary files /dev/null and b/tests/phpunit/data/css/simple-ltr.gif differ
diff --git a/tests/phpunit/data/css/simple-rtl.gif b/tests/phpunit/data/css/simple-rtl.gif
new file mode 100644 (file)
index 0000000..f9e7531
Binary files /dev/null and b/tests/phpunit/data/css/simple-rtl.gif differ
diff --git a/tests/phpunit/data/css/test.css b/tests/phpunit/data/css/test.css
new file mode 100644 (file)
index 0000000..bf589ad
--- /dev/null
@@ -0,0 +1,12 @@
+/* All of the combinations should result in the same output in LTR and RTL mode. */
+
+/*@noflip*/ .selector { /*@embed*/ background-image: url(simple-ltr.gif); }
+
+/*@noflip*/ .selector { background-image: /*@embed*/ url(simple-ltr.gif); }
+
+/* Doesn't work! */
+/*.selector { /*@noflip* / /*@embed* / background-image: url(simple-ltr.gif); }*/
+
+.selector { /*@embed*/ /*@noflip*/ background-image: url(simple-ltr.gif); }
+
+.selector { /*@noflip*/ background-image: /*@embed*/ url(simple-ltr.gif); }
index bd6b3f2..12ec9dd 100644 (file)
@@ -90,6 +90,36 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
                $this->assertStringEqualsFile( $basePath . '/styles.css', $styles['all'] );
        }
 
+       /**
+        * What happens when you mix @embed and @noflip?
+        * This really is an integration test, but oh well.
+        */
+       public function testMixedCssAnnotations(  ) {
+               $basePath = __DIR__ . '/../../data/css';
+               $testModule = new ResourceLoaderFileModule( array(
+                       'localBasePath' => $basePath,
+                       'styles' => array( 'test.css' ),
+               ) );
+               $expectedModule = new ResourceLoaderFileModule( array(
+                       'localBasePath' => $basePath,
+                       'styles' => array( 'expected.css' ),
+               ) );
+
+               $contextLtr = self::getResourceLoaderContext( 'en' );
+               $contextRtl = self::getResourceLoaderContext( 'he' );
+
+               $this->assertEquals(
+                       $expectedModule->getStyles( $contextLtr ),
+                       str_replace( '/*@noflip*/ ', '', $testModule->getStyles( $contextLtr ) ),
+                       "/*@noflip*/ with /*@embed*/ gives correct results in LTR mode"
+               );
+               $this->assertEquals(
+                       $expectedModule->getStyles( $contextLtr ),
+                       str_replace( '/*@noflip*/ ', '', $testModule->getStyles( $contextRtl ) ),
+                       "/*@noflip*/ with /*@embed*/ gives correct results in RTL mode"
+               );
+       }
+
        /**
         * @dataProvider providePackedModules
         * @covers ResourceLoader::makePackedModulesString