ResourceLoaderFileModule::readStyleFile() both reads a style file from disk and processes it through LESS, CSSJanus and CSSMin. Factor out the processing part into ResourceLoaderFileModule::processStyle(), which takes a string of unprocessed CSS/LESS rather than a file. This is needed for future support for styles that don't come (directly) from a file, but are generated through packageFiles. Other changes: - Use a hash of the source instead of the file name in the cache keys for the LESS compilation output - Also prefix the cache key with 'resourceloader' while we're changing it anyway - LESS compilation no longer adds the source file itself as a dependency - Don't pass down $flip, just use $this>getFlip() Change-Id: I86e880d06af724f0fbae93e042c85e0395771912
53 lines
1.4 KiB
PHP
53 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>
|
|
* @coversNothing
|
|
*/
|
|
class LessFileCompilationTest extends ResourceLoaderTestCase {
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
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->assertIsReadable( $this->file, "$thisString must refer to a readable file" );
|
|
|
|
$rlContext = $this->getResourceLoaderContext();
|
|
|
|
// Bleh
|
|
$method = new ReflectionMethod( $this->module, 'compileLessString' );
|
|
$method->setAccessible( true );
|
|
$fileContents = file_get_contents( $this->file );
|
|
$this->assertNotNull( $method->invoke( $this->module, $fileContents, $this->file, $rlContext ) );
|
|
}
|
|
|
|
public function toString() : string {
|
|
$moduleName = $this->module->getName();
|
|
|
|
return "{$this->file} in the \"{$moduleName}\" module";
|
|
}
|
|
}
|