From 90c13419f0899218ac5437e6102658dd6e73b63f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Mon, 18 Aug 2014 14:56:18 +0200 Subject: [PATCH] Add a test for mixed /*@noflip*/ and /*@embed*/ CSS annotations 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 | 4 +-- tests/phpunit/data/css/expected.css | 12 +++++++ tests/phpunit/data/css/simple-ltr.gif | Bin 0 -> 35 bytes tests/phpunit/data/css/simple-rtl.gif | Bin 0 -> 35 bytes tests/phpunit/data/css/test.css | 12 +++++++ .../resourceloader/ResourceLoaderTest.php | 30 ++++++++++++++++++ 6 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 tests/phpunit/data/css/expected.css create mode 100644 tests/phpunit/data/css/simple-ltr.gif create mode 100644 tests/phpunit/data/css/simple-rtl.gif create mode 100644 tests/phpunit/data/css/test.css diff --git a/tests/phpunit/ResourceLoaderTestCase.php b/tests/phpunit/ResourceLoaderTestCase.php index f316f56317..96eedb4940 100644 --- a/tests/phpunit/ResourceLoaderTestCase.php +++ b/tests/phpunit/ResourceLoaderTestCase.php @@ -1,10 +1,10 @@ '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 index 0000000000..74eb21eff3 --- /dev/null +++ b/tests/phpunit/data/css/expected.css @@ -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 index 0000000000000000000000000000000000000000..13c43e906cb71abe87b47a5e4b352ccbe9567d91 GIT binary patch literal 35 mcmZ?wbhEHbWMp7uXkcLY&%j{7z@Wnb1RxOxCMFj~25SIdKLiW_ literal 0 HcmV?d00001 diff --git a/tests/phpunit/data/css/simple-rtl.gif b/tests/phpunit/data/css/simple-rtl.gif new file mode 100644 index 0000000000000000000000000000000000000000..f9e7531658b443353f131a0d45f53f08cf4af77e GIT binary patch literal 35 mcmZ?wbhEHbWMp7uXkcIfVgm*S9Uue9XJlYtVsc?*um%8B)dP(H literal 0 HcmV?d00001 diff --git a/tests/phpunit/data/css/test.css b/tests/phpunit/data/css/test.css new file mode 100644 index 0000000000..bf589ad4d3 --- /dev/null +++ b/tests/phpunit/data/css/test.css @@ -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); } diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php index bd6b3f2329..12ec9ddde2 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php @@ -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 -- 2.20.1