From efabc31da242c7596116e5851a5384737ce3113e Mon Sep 17 00:00:00 2001 From: Erik Bernhardson Date: Tue, 22 Apr 2014 19:16:53 -0700 Subject: [PATCH] Resolve complex arguments to LESS helper functions The icons in Flow and the Compact Personal Bar beta feature are missing, their generated background-image 7 is empty. The lessphp implementation passes full data frames into the helper functions. Utilize the now-public compileValue method of less to evaluate the data frame into a string. Additionally adds a small abstraction to run pairs of less/css files as unit tests by executing the less file and comparing it to the equivalent css file. Change-Id: I1704f84638d86a0e6e6b9c190972ab19180bd484 --- .../ResourceLoaderLESSFunctions.php | 4 +-- .../resourceloader/ResourceLoaderLESSTest.php | 28 +++++++++++++++++++ .../fixtures/001-embeddable.css | 9 ++++++ .../fixtures/001-embeddable.less | 20 +++++++++++++ 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 tests/phpunit/includes/resourceloader/ResourceLoaderLESSTest.php create mode 100644 tests/phpunit/includes/resourceloader/fixtures/001-embeddable.css create mode 100644 tests/phpunit/includes/resourceloader/fixtures/001-embeddable.less diff --git a/includes/resourceloader/ResourceLoaderLESSFunctions.php b/includes/resourceloader/ResourceLoaderLESSFunctions.php index c7570f6435..e016a3308c 100644 --- a/includes/resourceloader/ResourceLoaderLESSFunctions.php +++ b/includes/resourceloader/ResourceLoaderLESSFunctions.php @@ -37,7 +37,7 @@ class ResourceLoaderLESSFunctions { */ public static function embeddable( $frame, $less ) { $base = pathinfo( $less->parser->sourceName, PATHINFO_DIRNAME ); - $url = $frame[2][0]; + $url = trim( $less->compileValue( $frame ), '"\'' ); $file = realpath( $base . '/' . $url ); return $less->toBool( $file && strpos( $url, '//' ) === false @@ -57,7 +57,7 @@ class ResourceLoaderLESSFunctions { */ public static function embed( $frame, $less ) { $base = pathinfo( $less->parser->sourceName, PATHINFO_DIRNAME ); - $url = $frame[2][0]; + $url = trim( $less->compileValue( $frame ), '"\'' ); $file = realpath( $base . '/' . $url ); $data = CSSMin::encodeImageAsDataURI( $file ); diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderLESSTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderLESSTest.php new file mode 100644 index 0000000000..75e54d3582 --- /dev/null +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderLESSTest.php @@ -0,0 +1,28 @@ +fail( "No css file found to assert equal to $lessFile" ); + return; + } + + $expect = file_get_contents( $cssFile ); + $content = file_get_contents( $lessFile ); + $result = ResourceLoader::getLessCompiler()->compile( $content, $lessFile ); + $this->assertEquals( $expect, $result ); + } +} diff --git a/tests/phpunit/includes/resourceloader/fixtures/001-embeddable.css b/tests/phpunit/includes/resourceloader/fixtures/001-embeddable.css new file mode 100644 index 0000000000..b291c5e0c7 --- /dev/null +++ b/tests/phpunit/includes/resourceloader/fixtures/001-embeddable.css @@ -0,0 +1,9 @@ +.box { + content: not-embeddable; +} +.box { + content: embeddable; +} +.box { + content: embeddable; +} diff --git a/tests/phpunit/includes/resourceloader/fixtures/001-embeddable.less b/tests/phpunit/includes/resourceloader/fixtures/001-embeddable.less new file mode 100644 index 0000000000..7018aa254d --- /dev/null +++ b/tests/phpunit/includes/resourceloader/fixtures/001-embeddable.less @@ -0,0 +1,20 @@ +@base: '../fixtures/'; + +.helper(@url) when (embeddable(@url)) { + content: embeddable; +} +.helper(@url) when not (embeddable(@url)) { + content: not-embeddable; +} + +.box { + .helper('path/to/nonexistent/file'); +} + +.box { + .helper('001-embeddable.css'); +} + +.box { + .helper("@{base}001-embeddable.css"); +} -- 2.20.1