* Remove ResourceLoaderFileModule::getLessCompiler(). There is no reason for a
module to need to get a compiler in a different manner than
ResourceLoader::getLessCompiler().
* Add ResourceLoaderModule::getLessVars(). This method provides a means for
subclasses to easily inject custom LESS variables. The default implementation
simply returns an empty array.
* Make the $context parameter for ResourceLoaderFileModule::readStyleFiles()
non-optional (via graceful deprecation). The only callers I found were either
already calling it with a ResourceLoader context, or had a perfectly usable
ResourceLoaderContext in local scope.
* Make ResourceLoaderFileModule::{readStyleFile,getLessCompiler} require a
context. These methods are protected, so I didn't bother with a deprecation.
* Call ksort() on the LESS variables array in the only place it matters -- when
hashing its serialized representation to construct a cache lookup key. This
relieves getLessVars() subclasses from having to remember to re-sort the
variables array if they modify it.
* These changes make it possible to substantially simplify
ResourceLoaderEditToolbarModule, because the only thing it needs to do now is
implement its own getLessVars() method.
* This also allows it to be versioned like any other ResourceLoaderFileModule,
rather than having to use enableModuleContentVersion().
Change-Id: Ic3eab71691e502bfe19bdf4eb6f82cc679a7782f
54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Modelled on Sebastian Bergmann's PHPUnit_Extensions_PhptTestCase class.
|
|
*
|
|
* @see https://github.com/sebastianbergmann/phpunit/blob/master/src/Extensions/PhptTestCase.php
|
|
* @author Sam Smith <samsmith@wikimedia.org>
|
|
*/
|
|
class LessFileCompilationTest extends ResourceLoaderTestCase {
|
|
|
|
/**
|
|
* @var string $file
|
|
*/
|
|
protected $file;
|
|
|
|
/**
|
|
* @var ResourceLoaderModule The ResourceLoader module that contains
|
|
* the file
|
|
*/
|
|
protected $module;
|
|
|
|
/**
|
|
* @param string $file
|
|
* @param ResourceLoaderModule $module The ResourceLoader module that
|
|
* contains the file
|
|
*/
|
|
public function __construct( $file, ResourceLoaderModule $module ) {
|
|
parent::__construct( 'testLessFileCompilation' );
|
|
|
|
$this->file = $file;
|
|
$this->module = $module;
|
|
}
|
|
|
|
public function testLessFileCompilation() {
|
|
$thisString = $this->toString();
|
|
$this->assertTrue(
|
|
is_string( $this->file ) && is_file( $this->file ) && is_readable( $this->file ),
|
|
"$thisString must refer to a readable file"
|
|
);
|
|
|
|
$rlContext = $this->getResourceLoaderContext();
|
|
|
|
// Bleh
|
|
$method = new ReflectionMethod( $this->module, 'compileLessFile' );
|
|
$method->setAccessible( true );
|
|
$this->assertNotNull( $method->invoke( $this->module, $this->file, $rlContext ) );
|
|
}
|
|
|
|
public function toString() {
|
|
$moduleName = $this->module->getName();
|
|
|
|
return "{$this->file} in the \"{$moduleName}\" module";
|
|
}
|
|
}
|