Merge "Add a test for mixed /*@noflip*/ and /*@embed*/ CSS annotations"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 26 Aug 2014 19:55:05 +0000 (19:55 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 26 Aug 2014 19:55:05 +0000 (19:55 +0000)
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