wiki.techinc.nl/tests/phpunit/LessFileCompilationTest.php

54 lines
1.4 KiB
PHP
Raw Normal View History

<?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
*/
Revamp classic edit toolbar not to hardcode paths in HTML Also, try out a way to have per-module LESS variables defined in PHP. This might come in handy in the future… Maybe for skin theme support? (I recommend reviewing the file changes in the order below. :D) includes/resourceloader/ResourceLoaderFileModule.php * Pass the context (ResourceLoaderContext) deeper down via readStyleFiles() and readStyleFile(). We need it to compile the .less files for the right language. * Extract LESS compiler creation to getLessCompiler(). * Allow passing a LESS compiler instance to compileLessFile(), rather than getting one after the method is called. All of the changes are backwards-compatible. includes/resourceloader/ResourceLoaderEditToolbarModule.php * New module to support getting the language data and passing it to LESS variables. It might be a good idea to factor out a reusable class for a LESS module with additional variables, but that would require more attention to design than I gave it. resources/src/mediawiki.action/mediawiki.action.edit.toolbar/mediawiki.action.edit.toolbar.less * Glue code to use the language data defined by the module above and put it in final CSS. includes/EditPage.php * Do not hardcode image URLs in output HTML, as they are provided in CSS now. This gets rid of some usage of globals. In fact, we should be able to finally move the inline JavaScript calls out of getEditToolbar(), but I'm already introducing too many changes for one patch. That can be done later. languages/Language.php * Add getImageFiles() to complement existing getImageFile() method. Misleadingly named, it returns paths for images for the toolbar only (and no other ones at all). skins/common/ → resources/src/mediawiki.action/mediawiki.action.edit.toolbar/ * Moved all of the button images to new location. Also, boring cleanup that was harder before because we treated the paths as public API: * Placed default ones in en/ subdirectory. * Renamed cyrl/ to ru/. * Renamed ksh/button_S_italic.png → ksh/button_italic.png. languages/messages/ * Adjusting paths and filenames for the changes above. resources/src/mediawiki.action/mediawiki.action.edit.css resources/src/mediawiki.action/mediawiki.action.edit.js * Added styles and updated the script to make it possible to have non-<img> elements as toolbar buttons. * Consolidated styles that were already required, but defined somewhere else: * `cursor: pointer;` (from shared.css) * `vertical-align: middle;` (from commonElements.css) Bug: 69277 Change-Id: I39d8ed4258c7da0fe4fe4c665cdb26c86420769c
2014-08-20 13:13:43 +00:00
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();
Revamp classic edit toolbar not to hardcode paths in HTML Also, try out a way to have per-module LESS variables defined in PHP. This might come in handy in the future… Maybe for skin theme support? (I recommend reviewing the file changes in the order below. :D) includes/resourceloader/ResourceLoaderFileModule.php * Pass the context (ResourceLoaderContext) deeper down via readStyleFiles() and readStyleFile(). We need it to compile the .less files for the right language. * Extract LESS compiler creation to getLessCompiler(). * Allow passing a LESS compiler instance to compileLessFile(), rather than getting one after the method is called. All of the changes are backwards-compatible. includes/resourceloader/ResourceLoaderEditToolbarModule.php * New module to support getting the language data and passing it to LESS variables. It might be a good idea to factor out a reusable class for a LESS module with additional variables, but that would require more attention to design than I gave it. resources/src/mediawiki.action/mediawiki.action.edit.toolbar/mediawiki.action.edit.toolbar.less * Glue code to use the language data defined by the module above and put it in final CSS. includes/EditPage.php * Do not hardcode image URLs in output HTML, as they are provided in CSS now. This gets rid of some usage of globals. In fact, we should be able to finally move the inline JavaScript calls out of getEditToolbar(), but I'm already introducing too many changes for one patch. That can be done later. languages/Language.php * Add getImageFiles() to complement existing getImageFile() method. Misleadingly named, it returns paths for images for the toolbar only (and no other ones at all). skins/common/ → resources/src/mediawiki.action/mediawiki.action.edit.toolbar/ * Moved all of the button images to new location. Also, boring cleanup that was harder before because we treated the paths as public API: * Placed default ones in en/ subdirectory. * Renamed cyrl/ to ru/. * Renamed ksh/button_S_italic.png → ksh/button_italic.png. languages/messages/ * Adjusting paths and filenames for the changes above. resources/src/mediawiki.action/mediawiki.action.edit.css resources/src/mediawiki.action/mediawiki.action.edit.js * Added styles and updated the script to make it possible to have non-<img> elements as toolbar buttons. * Consolidated styles that were already required, but defined somewhere else: * `cursor: pointer;` (from shared.css) * `vertical-align: middle;` (from commonElements.css) Bug: 69277 Change-Id: I39d8ed4258c7da0fe4fe4c665cdb26c86420769c
2014-08-20 13:13:43 +00:00
// Bleh
$method = new ReflectionMethod( $this->module, 'compileLessString' );
Revamp classic edit toolbar not to hardcode paths in HTML Also, try out a way to have per-module LESS variables defined in PHP. This might come in handy in the future… Maybe for skin theme support? (I recommend reviewing the file changes in the order below. :D) includes/resourceloader/ResourceLoaderFileModule.php * Pass the context (ResourceLoaderContext) deeper down via readStyleFiles() and readStyleFile(). We need it to compile the .less files for the right language. * Extract LESS compiler creation to getLessCompiler(). * Allow passing a LESS compiler instance to compileLessFile(), rather than getting one after the method is called. All of the changes are backwards-compatible. includes/resourceloader/ResourceLoaderEditToolbarModule.php * New module to support getting the language data and passing it to LESS variables. It might be a good idea to factor out a reusable class for a LESS module with additional variables, but that would require more attention to design than I gave it. resources/src/mediawiki.action/mediawiki.action.edit.toolbar/mediawiki.action.edit.toolbar.less * Glue code to use the language data defined by the module above and put it in final CSS. includes/EditPage.php * Do not hardcode image URLs in output HTML, as they are provided in CSS now. This gets rid of some usage of globals. In fact, we should be able to finally move the inline JavaScript calls out of getEditToolbar(), but I'm already introducing too many changes for one patch. That can be done later. languages/Language.php * Add getImageFiles() to complement existing getImageFile() method. Misleadingly named, it returns paths for images for the toolbar only (and no other ones at all). skins/common/ → resources/src/mediawiki.action/mediawiki.action.edit.toolbar/ * Moved all of the button images to new location. Also, boring cleanup that was harder before because we treated the paths as public API: * Placed default ones in en/ subdirectory. * Renamed cyrl/ to ru/. * Renamed ksh/button_S_italic.png → ksh/button_italic.png. languages/messages/ * Adjusting paths and filenames for the changes above. resources/src/mediawiki.action/mediawiki.action.edit.css resources/src/mediawiki.action/mediawiki.action.edit.js * Added styles and updated the script to make it possible to have non-<img> elements as toolbar buttons. * Consolidated styles that were already required, but defined somewhere else: * `cursor: pointer;` (from shared.css) * `vertical-align: middle;` (from commonElements.css) Bug: 69277 Change-Id: I39d8ed4258c7da0fe4fe4c665cdb26c86420769c
2014-08-20 13:13:43 +00:00
$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";
}
}