2017-02-20 04:33:24 +00:00
|
|
|
<?php
|
|
|
|
|
2022-02-06 14:39:49 +00:00
|
|
|
use MediaWiki\Extension\TemplateStyles\TemplateStylesContent;
|
|
|
|
|
2017-02-20 04:33:24 +00:00
|
|
|
/**
|
|
|
|
* @group TemplateStyles
|
2022-02-06 14:39:49 +00:00
|
|
|
* @covers \MediaWiki\Extension\TemplateStyles\TemplateStylesContent
|
2017-02-20 04:33:24 +00:00
|
|
|
*/
|
|
|
|
class TemplateStylesContentTest extends TextContentTest {
|
|
|
|
|
2021-07-23 22:49:15 +00:00
|
|
|
protected function setUp(): void {
|
2017-02-20 04:33:24 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->setMwGlobals( [
|
|
|
|
'wgTextModelsToParse' => [
|
|
|
|
'sanitized-css',
|
|
|
|
],
|
|
|
|
'wgTemplateStylesMaxStylesheetSize' => 1024000,
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function newContent( $text ) {
|
|
|
|
return new TemplateStylesContent( $text );
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function dataGetParserOutput() {
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'Template:Test/styles.css',
|
|
|
|
'sanitized-css',
|
|
|
|
".hello { content: 'world'; color: bogus; }\n\n<ok>\n",
|
2021-03-26 23:59:00 +00:00
|
|
|
// phpcs:ignore Generic.Files.LineLength
|
2017-02-20 04:33:24 +00:00
|
|
|
"<pre class=\"mw-code mw-css\" dir=\"ltr\">\n.hello { content: 'world'; color: bogus; }\n\n<ok>\n\n</pre>",
|
|
|
|
[
|
|
|
|
'Warnings' => [
|
|
|
|
'Unexpected end of stylesheet in rule at line 4 character 1.',
|
|
|
|
'Invalid or unsupported value for property <code>color</code> at line 1 character 35.',
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'Template:Test/styles.css',
|
|
|
|
'sanitized-css',
|
|
|
|
"/* hello [[world]] */\n",
|
|
|
|
"<pre class=\"mw-code mw-css\" dir=\"ltr\">\n/* hello [[world]] */\n\n</pre>",
|
|
|
|
[
|
|
|
|
'Links' => [
|
|
|
|
[ 'World' => 0 ]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function dataPreSaveTransform() {
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'hello this is ~~~',
|
|
|
|
'hello this is ~~~',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
|
|
|
|
'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
" Foo \n ",
|
|
|
|
" Foo",
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function dataPreloadTransform() {
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'hello this is ~~~',
|
|
|
|
'hello this is ~~~',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
|
|
|
|
'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetModel() {
|
|
|
|
$content = $this->newContent( 'hello world.' );
|
|
|
|
|
|
|
|
$this->assertEquals( 'sanitized-css', $content->getModel() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetContentHandler() {
|
|
|
|
$content = $this->newContent( 'hello world.' );
|
|
|
|
|
|
|
|
$this->assertEquals( 'sanitized-css', $content->getContentHandler()->getModelID() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redirects aren't supported
|
|
|
|
*/
|
|
|
|
public static function provideUpdateRedirect() {
|
2021-03-26 23:59:00 +00:00
|
|
|
// phpcs:disable Generic.Files.LineLength
|
2017-02-20 04:33:24 +00:00
|
|
|
return [
|
|
|
|
[
|
|
|
|
'#REDIRECT [[Someplace]]',
|
|
|
|
'#REDIRECT [[Someplace]]',
|
|
|
|
],
|
|
|
|
|
|
|
|
// The style supported by CssContent
|
|
|
|
[
|
|
|
|
'/* #REDIRECT */@import url(//example.org/w/index.php?title=MediaWiki:MonoBook.css&action=raw&ctype=text/css);',
|
|
|
|
'/* #REDIRECT */@import url(//example.org/w/index.php?title=MediaWiki:MonoBook.css&action=raw&ctype=text/css);',
|
|
|
|
],
|
|
|
|
];
|
2021-03-26 23:59:00 +00:00
|
|
|
// phpcs:enable
|
2017-02-20 04:33:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideGetRedirectTarget
|
|
|
|
*/
|
|
|
|
public function testGetRedirectTarget( $title, $text ) {
|
|
|
|
$this->setMwGlobals( [
|
|
|
|
'wgServer' => '//example.org',
|
|
|
|
'wgScriptPath' => '/w',
|
|
|
|
'wgScript' => '/w/index.php',
|
|
|
|
] );
|
|
|
|
$content = $this->newContent( $text );
|
|
|
|
$target = $content->getRedirectTarget();
|
|
|
|
$this->assertEquals( $title, $target ? $target->getPrefixedText() : null );
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function provideGetRedirectTarget() {
|
2021-03-26 23:59:00 +00:00
|
|
|
// phpcs:disable Generic.Files.LineLength
|
2017-02-20 04:33:24 +00:00
|
|
|
return [
|
|
|
|
[ null, "/* #REDIRECT */@import url(//example.org/w/index.php?title=MediaWiki:MonoBook.css&action=raw&ctype=text/css);" ],
|
|
|
|
[ null, "/* #REDIRECT */@import url(//example.org/w/index.php?title=User:FooBar/common.css&action=raw&ctype=text/css);" ],
|
|
|
|
[ null, "/* #REDIRECT */@import url(//example.org/w/index.php?title=Gadget:FooBaz.css&action=raw&ctype=text/css);" ],
|
|
|
|
[ null, "@import url(//example.org/w/index.php?title=Gadget:FooBaz.css&action=raw&ctype=text/css);" ],
|
|
|
|
[ null, "/* #REDIRECT */@import url(//example.com/w/index.php?title=Gadget:FooBaz.css&action=raw&ctype=text/css);" ],
|
|
|
|
];
|
2021-03-26 23:59:00 +00:00
|
|
|
// phpcs:enable
|
2017-02-20 04:33:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function dataEquals() {
|
|
|
|
return [
|
|
|
|
[ new TemplateStylesContent( 'hallo' ), null, false ],
|
|
|
|
[ new TemplateStylesContent( 'hallo' ), new TemplateStylesContent( 'hallo' ), true ],
|
|
|
|
[ new TemplateStylesContent( 'hallo' ), new CssContent( 'hallo' ), false ],
|
|
|
|
[ new TemplateStylesContent( 'hallo' ), new WikitextContent( 'hallo' ), false ],
|
|
|
|
[ new TemplateStylesContent( 'hallo' ), new TemplateStylesContent( 'HALLO' ), false ],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataEquals
|
|
|
|
*/
|
|
|
|
public function testEquals( Content $a, Content $b = null, $equal = false ) {
|
|
|
|
$this->assertEquals( $equal, $a->equals( $b ) );
|
|
|
|
}
|
|
|
|
}
|