From f4d1039a2017499bd8773dd319ae88040ecbd1f2 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sat, 19 May 2018 20:37:04 +0200 Subject: [PATCH] resourceloader: Add test case for ResourceLoader::getLessCompiler This was previously covered implicitly by an unrelated test. Change that test (dependency.less) to use ../ to access the file directly so that that test case is only about tracking dependencies and testing the parser. Then, add a second case that tests the use of import dirs. Bug: T140807 Change-Id: Ie85abffe313922c03b3e146422f36b1d6a79743d --- tests/phpunit/data/less/module/dependency.less | 2 +- .../data/less/module/use-import-dir.less | 6 ++++++ .../resourceloader/ResourceLoaderTest.php | 18 +++++++++++++++--- 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 tests/phpunit/data/less/module/use-import-dir.less diff --git a/tests/phpunit/data/less/module/dependency.less b/tests/phpunit/data/less/module/dependency.less index c7725a2520..110e00bdbc 100644 --- a/tests/phpunit/data/less/module/dependency.less +++ b/tests/phpunit/data/less/module/dependency.less @@ -1,3 +1,3 @@ -@import "test.common.mixins"; +@import "../common/test.common.mixins"; @unitTestColor: green; diff --git a/tests/phpunit/data/less/module/use-import-dir.less b/tests/phpunit/data/less/module/use-import-dir.less new file mode 100644 index 0000000000..4710bc64d9 --- /dev/null +++ b/tests/phpunit/data/less/module/use-import-dir.less @@ -0,0 +1,6 @@ +@import "test.common.mixins"; + +/* @noflip */ +.unit-tests { + .test-mixin(green); +} diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php index e811d874ff..95006aa923 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php @@ -8,9 +8,7 @@ class ResourceLoaderTest extends ResourceLoaderTestCase { parent::setUp(); $this->setMwGlobals( [ - 'wgResourceLoaderLESSImportPaths' => [ - dirname( dirname( __DIR__ ) ) . '/data/less/common', - ], + 'wgResourceLoaderLESSImportPaths' => [], 'wgResourceLoaderLESSVars' => [ 'foo' => '2px', 'Foo' => '#eeeeee', @@ -264,6 +262,20 @@ class ResourceLoaderTest extends ResourceLoaderTestCase { $this->assertStringEqualsFile( $basePath . '/styles.css', $styles['all'] ); } + /** + * @covers ResourceLoader::getLessCompiler + */ + public function testLessImportDirs() { + $rl = new EmptyResourceLoader(); + $lc = $rl->getLessCompiler(); + $basePath = dirname( dirname( __DIR__ ) ) . '/data/less'; + $lc->SetImportDirs( [ + "$basePath/common" => '', + ] ); + $css = $lc->parseFile( "$basePath/module/use-import-dir.less" )->getCss(); + $this->assertStringEqualsFile( "$basePath/module/styles.css", $css ); + } + public static function providePackedModules() { return [ [ -- 2.20.1