3 * Checks that all Codex tokens have defaults defined in mediawiki.skin.defaults.less
7 class CodexTokenDefaultsTest
extends MediaWikiIntegrationTestCase
{
9 public function testTokenDefaults() {
10 $resourcesPath = __DIR__
. '/../../../resources';
11 $codexTokensLess = "$resourcesPath/lib/codex-design-tokens/theme-wikimedia-ui.less";
12 $defaultsLess = "$resourcesPath/src/mediawiki.less/mediawiki.skin.defaults.less";
14 $codexVars = static::getVariableNames( $codexTokensLess );
15 $defaultVars = static::getVariableNames( $defaultsLess );
16 $missingVars = array_values( array_diff( $codexVars, $defaultVars ) );
17 $this->assertEquals( [], $missingVars );
20 protected static function getVariableNames( $lessFilePath ) {
21 // We'd like to do something like:
22 // $parser = new Less_Parser;
23 // $parser->parseFile( $lessFilePath, '' );
24 // $parser->getCss(); // Have to call this for ->getVariables() to work; discard the result
25 // return array_keys( $parser->getVariables() );
26 // But that doesn't work, the Less compiler appears to crash because of the calc() and rgba()
27 // calls in the variable values. Instead, use regexes :(
29 $fileContents = file_get_contents( $lessFilePath );
31 preg_match_all( '/^@([^:]+):/m', $fileContents, $matches, PREG_PATTERN_ORDER
);