Skins can choose to provide these values using Codex tokens by importing one of the Codex themes in their mediawiki.skin.variables.less. To guarantee that the variables corresponding to Codex tokens always exist, provide neutral fallback values for all of them in mediawiki.skin.defaults.less. To ensure that mediawiki.skin.defaults.less doesn't get out of sync with Codex when new tokens are added, add a structure test that verifies that every Codex token has a corresponding default variable. This isn't an ideal system, and we'll be able to handle this better once Codex has a real theme system (T286689) and we can upstream this set of neutral values into Codex itself. For now, keep (almost) all existing variables' values the same. This means overriding some of the values from Codex. We should consider whether some of these should be changed in a follow-up patch. The only values changed in this patch are: - @max-width-breakpoint-tablet from calc(719px) to 719px (no visual impact; but we should consider changing this to 1119px which is what it is in Codex) Bug: T325237 Change-Id: I04f9e48a1cf9dee915cf51e1e12b17ff0a595a06
34 lines
1.3 KiB
PHP
34 lines
1.3 KiB
PHP
<?php
|
|
/**
|
|
* Checks that all Codex tokens have defaults defined in mediawiki.skin.defaults.less
|
|
*
|
|
* @coversNothing
|
|
*/
|
|
class CodexTokenDefaultsTest extends MediaWikiIntegrationTestCase {
|
|
|
|
public function testTokenDefaults() {
|
|
$resourcesPath = __DIR__ . '/../../../resources';
|
|
$codexTokensLess = "$resourcesPath/lib/codex-design-tokens/theme-wikimedia-ui.less";
|
|
$defaultsLess = "$resourcesPath/src/mediawiki.less/mediawiki.skin.defaults.less";
|
|
|
|
$codexVars = static::getVariableNames( $codexTokensLess );
|
|
$defaultVars = static::getVariableNames( $defaultsLess );
|
|
$missingVars = array_values( array_diff( $codexVars, $defaultVars ) );
|
|
$this->assertEquals( [], $missingVars );
|
|
}
|
|
|
|
protected static function getVariableNames( $lessFilePath ) {
|
|
// We'd like to do something like:
|
|
// $parser = new Less_Parser;
|
|
// $parser->parseFile( $lessFilePath, '' );
|
|
// $parser->getCss(); // Have to call this for ->getVariables() to work; discard the result
|
|
// return array_keys( $parser->getVariables() );
|
|
// But that doesn't work, the Less compiler appears to crash because of the calc() and rgba()
|
|
// calls in the variable values. Instead, use regexes :(
|
|
|
|
$fileContents = file_get_contents( $lessFilePath );
|
|
$matches = null;
|
|
preg_match_all( '/^@([^:]+):/m', $fileContents, $matches, PREG_PATTERN_ORDER );
|
|
return $matches[1];
|
|
}
|
|
}
|