File: CodexTokenDefaultsTest.php

package info (click to toggle)
mediawiki 1%3A1.43.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 417,464 kB
  • sloc: php: 1,062,949; javascript: 664,290; sql: 9,714; python: 5,458; xml: 3,489; sh: 1,131; makefile: 64
file content (34 lines) | stat: -rw-r--r-- 1,371 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?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];
	}
}