Merge "Chinese Conversion Table Update 2017-6"
[lhc/web/wiklou.git] / tests / phpunit / includes / content / CssContentTest.php
1 <?php
2
3 /**
4 * @group ContentHandler
5 * @group Database
6 * ^--- needed, because we do need the database to test link updates
7 *
8 * @FIXME this should not extend JavaScriptContentTest.
9 */
10 class CssContentTest extends JavaScriptContentTest {
11
12 protected function setUp() {
13 parent::setUp();
14
15 // Anon user
16 $user = new User();
17 $user->setName( '127.0.0.1' );
18
19 $this->setMwGlobals( [
20 'wgUser' => $user,
21 'wgTextModelsToParse' => [
22 CONTENT_MODEL_CSS,
23 ]
24 ] );
25 }
26
27 public function newContent( $text ) {
28 return new CssContent( $text );
29 }
30
31 public static function dataGetParserOutput() {
32 return [
33 [
34 'MediaWiki:Test.css',
35 null,
36 "hello <world>\n",
37 "<pre class=\"mw-code mw-css\" dir=\"ltr\">\nhello &lt;world&gt;\n\n</pre>"
38 ],
39 [
40 'MediaWiki:Test.css',
41 null,
42 "/* hello [[world]] */\n",
43 "<pre class=\"mw-code mw-css\" dir=\"ltr\">\n/* hello [[world]] */\n\n</pre>",
44 [
45 'Links' => [
46 [ 'World' => 0 ]
47 ]
48 ]
49 ],
50
51 // TODO: more...?
52 ];
53 }
54
55 /**
56 * @covers CssContent::getModel
57 */
58 public function testGetModel() {
59 $content = $this->newContent( 'hello world.' );
60
61 $this->assertEquals( CONTENT_MODEL_CSS, $content->getModel() );
62 }
63
64 /**
65 * @covers CssContent::getContentHandler
66 */
67 public function testGetContentHandler() {
68 $content = $this->newContent( 'hello world.' );
69
70 $this->assertEquals( CONTENT_MODEL_CSS, $content->getContentHandler()->getModelID() );
71 }
72
73 /**
74 * Redirects aren't supported
75 */
76 public static function provideUpdateRedirect() {
77 return [
78 [
79 '#REDIRECT [[Someplace]]',
80 '#REDIRECT [[Someplace]]',
81 ],
82 ];
83 }
84
85 /**
86 * @covers CssContent::getRedirectTarget
87 * @dataProvider provideGetRedirectTarget
88 */
89 public function testGetRedirectTarget( $title, $text ) {
90 $this->setMwGlobals( [
91 'wgServer' => '//example.org',
92 'wgScriptPath' => '/w',
93 'wgScript' => '/w/index.php',
94 ] );
95 $content = new CssContent( $text );
96 $target = $content->getRedirectTarget();
97 $this->assertEquals( $title, $target ? $target->getPrefixedText() : null );
98 }
99
100 /**
101 * Keep this in sync with CssContentHandlerTest::provideMakeRedirectContent()
102 */
103 public static function provideGetRedirectTarget() {
104 // @codingStandardsIgnoreStart Generic.Files.LineLength
105 return [
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);" ],
109 # No #REDIRECT comment
110 [ null, "@import url(//example.org/w/index.php?title=Gadget:FooBaz.css&action=raw&ctype=text/css);" ],
111 # Wrong domain
112 [ null, "/* #REDIRECT */@import url(//example.com/w/index.php?title=Gadget:FooBaz.css&action=raw&ctype=text/css);" ],
113 ];
114 // @codingStandardsIgnoreEnd
115 }
116
117 public static function dataEquals() {
118 return [
119 [ new CssContent( 'hallo' ), null, false ],
120 [ new CssContent( 'hallo' ), new CssContent( 'hallo' ), true ],
121 [ new CssContent( 'hallo' ), new WikitextContent( 'hallo' ), false ],
122 [ new CssContent( 'hallo' ), new CssContent( 'HALLO' ), false ],
123 ];
124 }
125
126 /**
127 * @dataProvider dataEquals
128 * @covers CssContent::equals
129 */
130 public function testEquals( Content $a, Content $b = null, $equal = false ) {
131 $this->assertEquals( $equal, $a->equals( $b ) );
132 }
133 }