composer: * mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0 The following sniffs now pass and were enabled: * Generic.ControlStructures.InlineControlStructure * MediaWiki.PHPUnit.AssertCount.NotUsed npm: * svgo: 2.3.0 → 2.3.1 * https://npmjs.com/advisories/1754 (CVE-2021-33587) Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
145 lines
3.8 KiB
PHP
145 lines
3.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group ContentHandler
|
|
* @group Database
|
|
* ^--- needed, because we do need the database to test link updates
|
|
*/
|
|
class CssContentTest extends TextContentTest {
|
|
|
|
protected function setUp(): void {
|
|
parent::setUp();
|
|
|
|
$this->setMwGlobals( [
|
|
'wgTextModelsToParse' => [
|
|
CONTENT_MODEL_CSS,
|
|
]
|
|
] );
|
|
}
|
|
|
|
public function newContent( $text ) {
|
|
return new CssContent( $text );
|
|
}
|
|
|
|
public static function dataGetParserOutput() {
|
|
return [
|
|
[
|
|
'MediaWiki:Test.css',
|
|
null,
|
|
"hello <world>\n",
|
|
"<pre class=\"mw-code mw-css\" dir=\"ltr\">\nhello <world>\n\n</pre>"
|
|
],
|
|
[
|
|
'MediaWiki:Test.css',
|
|
null,
|
|
"/* hello [[world]] */\n",
|
|
"<pre class=\"mw-code mw-css\" dir=\"ltr\">\n/* hello [[world]] */\n\n</pre>",
|
|
[
|
|
'Links' => [
|
|
[ 'World' => 0 ]
|
|
]
|
|
]
|
|
],
|
|
|
|
// TODO: more...?
|
|
];
|
|
}
|
|
|
|
// XXX: currently, preSaveTransform is applied to styles. this may change or become optional.
|
|
public static function dataPreSaveTransform() {
|
|
return [
|
|
[ 'hello this is ~~~',
|
|
"hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
|
|
],
|
|
[ 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
|
|
'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
|
|
],
|
|
[ " Foo \n ",
|
|
" Foo",
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @covers CssContent::getModel
|
|
*/
|
|
public function testGetModel() {
|
|
$content = $this->newContent( 'hello world.' );
|
|
|
|
$this->assertEquals( CONTENT_MODEL_CSS, $content->getModel() );
|
|
}
|
|
|
|
/**
|
|
* @covers CssContent::getContentHandler
|
|
*/
|
|
public function testGetContentHandler() {
|
|
$content = $this->newContent( 'hello world.' );
|
|
|
|
$this->assertEquals( CONTENT_MODEL_CSS, $content->getContentHandler()->getModelID() );
|
|
}
|
|
|
|
/**
|
|
* Redirects aren't supported
|
|
*/
|
|
public static function provideUpdateRedirect() {
|
|
return [
|
|
[
|
|
'#REDIRECT [[Someplace]]',
|
|
'#REDIRECT [[Someplace]]',
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @covers CssContent::getRedirectTarget
|
|
* @dataProvider provideGetRedirectTarget
|
|
*/
|
|
public function testGetRedirectTarget( $title, $text ) {
|
|
$this->setMwGlobals( [
|
|
'wgServer' => '//example.org',
|
|
'wgScriptPath' => '/w',
|
|
'wgScript' => '/w/index.php',
|
|
] );
|
|
$content = new CssContent( $text );
|
|
$target = $content->getRedirectTarget();
|
|
$this->assertEquals( $title, $target ? $target->getPrefixedText() : null );
|
|
}
|
|
|
|
/**
|
|
* Keep this in sync with CssContentHandlerTest::provideMakeRedirectContent()
|
|
*/
|
|
public static function provideGetRedirectTarget() {
|
|
// phpcs:disable Generic.Files.LineLength
|
|
return [
|
|
[ 'MediaWiki:MonoBook.css', "/* #REDIRECT */@import url(//example.org/w/index.php?title=MediaWiki:MonoBook.css&action=raw&ctype=text/css);" ],
|
|
[ 'User:FooBar/common.css', "/* #REDIRECT */@import url(//example.org/w/index.php?title=User:FooBar/common.css&action=raw&ctype=text/css);" ],
|
|
[ 'Gadget:FooBaz.css', "/* #REDIRECT */@import url(//example.org/w/index.php?title=Gadget:FooBaz.css&action=raw&ctype=text/css);" ],
|
|
[
|
|
'User:😂/unicode.css',
|
|
'/* #REDIRECT */@import url(//example.org/w/index.php?title=User:%F0%9F%98%82/unicode.css&action=raw&ctype=text/css);'
|
|
],
|
|
# No #REDIRECT comment
|
|
[ null, "@import url(//example.org/w/index.php?title=Gadget:FooBaz.css&action=raw&ctype=text/css);" ],
|
|
# Wrong domain
|
|
[ null, "/* #REDIRECT */@import url(//example.com/w/index.php?title=Gadget:FooBaz.css&action=raw&ctype=text/css);" ],
|
|
];
|
|
// phpcs:enable
|
|
}
|
|
|
|
public static function dataEquals() {
|
|
return [
|
|
[ new CssContent( 'hallo' ), null, false ],
|
|
[ new CssContent( 'hallo' ), new CssContent( 'hallo' ), true ],
|
|
[ new CssContent( 'hallo' ), new WikitextContent( 'hallo' ), false ],
|
|
[ new CssContent( 'hallo' ), new CssContent( 'HALLO' ), false ],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider dataEquals
|
|
* @covers CssContent::equals
|
|
*/
|
|
public function testEquals( Content $a, Content $b = null, $equal = false ) {
|
|
$this->assertEquals( $equal, $a->equals( $b ) );
|
|
}
|
|
}
|