4 * @group ContentHandler
6 * ^--- needed, because we do need the database to test link updates
8 * @FIXME this should not extend JavaScriptContentTest.
10 class CssContentTest
extends JavaScriptContentTest
{
12 protected function setUp() {
17 $user->setName( '127.0.0.1' );
19 $this->setMwGlobals( [
21 'wgTextModelsToParse' => [
27 public function newContent( $text ) {
28 return new CssContent( $text );
31 public static function dataGetParserOutput() {
37 "<pre class=\"mw-code mw-css\" dir=\"ltr\">\nhello <world>\n\n</pre>"
42 "/* hello [[world]] */\n",
43 "<pre class=\"mw-code mw-css\" dir=\"ltr\">\n/* hello [[world]] */\n\n</pre>",
56 * @covers CssContent::getModel
58 public function testGetModel() {
59 $content = $this->newContent( 'hello world.' );
61 $this->assertEquals( CONTENT_MODEL_CSS
, $content->getModel() );
65 * @covers CssContent::getContentHandler
67 public function testGetContentHandler() {
68 $content = $this->newContent( 'hello world.' );
70 $this->assertEquals( CONTENT_MODEL_CSS
, $content->getContentHandler()->getModelID() );
74 * Redirects aren't supported
76 public static function provideUpdateRedirect() {
79 '#REDIRECT [[Someplace]]',
80 '#REDIRECT [[Someplace]]',
86 * @covers CssContent::getRedirectTarget
87 * @dataProvider provideGetRedirectTarget
89 public function testGetRedirectTarget( $title, $text ) {
90 $this->setMwGlobals( [
91 'wgServer' => '//example.org',
92 'wgScriptPath' => '/w',
93 'wgScript' => '/w/index.php',
95 $content = new CssContent( $text );
96 $target = $content->getRedirectTarget();
97 $this->assertEquals( $title, $target ?
$target->getPrefixedText() : null );
101 * Keep this in sync with CssContentHandlerTest::provideMakeRedirectContent()
103 public static function provideGetRedirectTarget() {
104 // phpcs:disable Generic.Files.LineLength
106 [ 'MediaWiki:MonoBook.css', "/* #REDIRECT */@import url(//example.org/w/index.php?title=MediaWiki:MonoBook.css&action=raw&ctype=text/css);" ],
107 [ 'User:FooBar/common.css', "/* #REDIRECT */@import url(//example.org/w/index.php?title=User:FooBar/common.css&action=raw&ctype=text/css);" ],
108 [ 'Gadget:FooBaz.css', "/* #REDIRECT */@import url(//example.org/w/index.php?title=Gadget:FooBaz.css&action=raw&ctype=text/css);" ],
110 'User:😂/unicode.css',
111 '/* #REDIRECT */@import url(//example.org/w/index.php?title=User:%F0%9F%98%82/unicode.css&action=raw&ctype=text/css);'
113 # No #REDIRECT comment
114 [ null, "@import url(//example.org/w/index.php?title=Gadget:FooBaz.css&action=raw&ctype=text/css);" ],
116 [ null, "/* #REDIRECT */@import url(//example.com/w/index.php?title=Gadget:FooBaz.css&action=raw&ctype=text/css);" ],
121 public static function dataEquals() {
123 [ new CssContent( 'hallo' ), null, false ],
124 [ new CssContent( 'hallo' ), new CssContent( 'hallo' ), true ],
125 [ new CssContent( 'hallo' ), new WikitextContent( 'hallo' ), false ],
126 [ new CssContent( 'hallo' ), new CssContent( 'HALLO' ), false ],
131 * @dataProvider dataEquals
132 * @covers CssContent::equals
134 public function testEquals( Content
$a, Content
$b = null, $equal = false ) {
135 $this->assertEquals( $equal, $a->equals( $b ) );