mediawiki-extensions-Templa.../tests/phpunit/TemplateStylesFontFaceAtRuleSanitizerTest.php
Brad Jorsch f99d171c80 Fix coverage
* Fix test for TemplateStylesFontFaceAtRuleSanitizer so it's actually run
* Hack up a broken Sanitizer to test a code path in
  TemplateStylesContent::sanitize() that handles such things.
* Ignore an InvalidArgumentException in TemplateStylesContent::processError()
  that's not worth checking. User input can't hit that, only logic bugs.
* Ignore TemplateStylesHooks::getConfig(), it's tested but gets called
  before PHPUnit starts counting.
* Test TemplateStylesHooksTest::onCodeEditorGetPageLanguage()
* Test $wgTemplateStylesDisable
* Test a back-compat code path in TemplateStylesHooks::handleTag().

Change-Id: I7078e5a353a624aa53fe72de7990b93a77b44cf6
2018-02-05 22:36:58 -05:00

92 lines
2.4 KiB
PHP

<?php
use Wikimedia\CSS\Grammar\MatcherFactory;
use Wikimedia\CSS\Parser\Parser;
use Wikimedia\CSS\Util;
/**
* @group TemplateStyles
* @covers TemplateStylesFontFaceAtRuleSanitizer
*/
class TemplateStylesFontFaceAtRuleSanitizerTest extends PHPUnit_Framework_TestCase {
/**
* @dataProvider provideRules
* @param string $input
* @param bool $handled
* @param string|null $output
* @param string|null $minified
* @param array $errors
* @param array $options
*/
public function testRules( $input, $handled, $output, $minified, $errors = [], $options = [] ) {
$san = new TemplateStylesFontFaceAtRuleSanitizer( new MatcherFactory() );
$rule = Parser::newFromString( $input )->parseRule();
$oldRule = clone $rule;
$this->assertSame( $handled, $san->handlesRule( $rule ) );
$ret = $san->sanitize( $rule );
$this->assertSame( $errors, $san->getSanitizationErrors() );
if ( $output === null ) {
$this->assertNull( $ret );
} else {
$this->assertNotNull( $ret );
$this->assertSame( $output, (string)$ret );
$this->assertSame( $minified, Util::stringify( $ret, [ 'minify' => true ] ) );
}
$this->assertEquals( (string)$oldRule, (string)$rule, 'Rule wasn\'t overwritten' );
}
public static function provideRules() {
return [
'non-prefixed font family as string' => [
'@font-face {
font-family: "foo bar";
}',
true,
'@font-face {}',
'@font-face{}',
[
[ 'bad-value-for-property', 2, 19, 'font-family' ],
]
],
'non-prefixed font family as idents' => [
'@font-face {
font-family: foo bar;
}',
true,
'@font-face {}',
'@font-face{}',
[
[ 'bad-value-for-property', 2, 19, 'font-family' ],
]
],
'prefixed font family as string' => [
'@font-face {
font-family: "TemplateStyles foo bar";
}',
true,
'@font-face { font-family: "TemplateStyles foo bar"; }',
'@font-face{font-family:"TemplateStyles foo bar"}',
],
'non-prefixed font family as idents (1)' => [
'@font-face {
font-family: TemplateStyles foo bar;
}',
true,
'@font-face { font-family: TemplateStyles foo bar; }',
'@font-face{font-family:TemplateStyles foo bar}',
],
'non-prefixed font family as idents (2)' => [
'@font-face {
font-family: TemplateStylesFoo bar;
}',
true,
'@font-face { font-family: TemplateStylesFoo bar; }',
'@font-face{font-family:TemplateStylesFoo bar}',
],
];
}
}