Merge "Genderize Special:Preferences"
[lhc/web/wiklou.git] / tests / phpunit / includes / content / JavaScriptContentTest.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 class JavaScriptContentTest extends TextContentTest {
9
10 public function newContent( $text ) {
11 return new JavaScriptContent( $text );
12 }
13
14 public static function dataGetParserOutput() {
15 return array(
16 array(
17 'MediaWiki:Test.js',
18 null,
19 "hello <world>\n",
20 "<pre class=\"mw-code mw-js\" dir=\"ltr\">\nhello &lt;world&gt;\n\n</pre>"
21 ),
22 array(
23 'MediaWiki:Test.js',
24 null,
25 "hello(); // [[world]]\n",
26 "<pre class=\"mw-code mw-js\" dir=\"ltr\">\nhello(); // [[world]]\n\n</pre>",
27 array(
28 'Links' => array(
29 array( 'World' => 0 )
30 )
31 )
32 ),
33
34 // TODO: more...?
35 );
36 }
37
38 // XXX: Unused function
39 public static function dataGetSection() {
40 return array(
41 array( WikitextContentTest::$sections,
42 '0',
43 null
44 ),
45 array( WikitextContentTest::$sections,
46 '2',
47 null
48 ),
49 array( WikitextContentTest::$sections,
50 '8',
51 null
52 ),
53 );
54 }
55
56 // XXX: Unused function
57 public static function dataReplaceSection() {
58 return array(
59 array( WikitextContentTest::$sections,
60 '0',
61 'No more',
62 null,
63 null
64 ),
65 array( WikitextContentTest::$sections,
66 '',
67 'No more',
68 null,
69 null
70 ),
71 array( WikitextContentTest::$sections,
72 '2',
73 "== TEST ==\nmore fun",
74 null,
75 null
76 ),
77 array( WikitextContentTest::$sections,
78 '8',
79 'No more',
80 null,
81 null
82 ),
83 array( WikitextContentTest::$sections,
84 'new',
85 'No more',
86 'New',
87 null
88 ),
89 );
90 }
91
92 public function testAddSectionHeader( ) {
93 $content = $this->newContent( 'hello world' );
94 $c = $content->addSectionHeader( 'test' );
95
96 $this->assertTrue( $content->equals( $c ) );
97 }
98
99 // XXX: currently, preSaveTransform is applied to scripts. this may change or become optional.
100 public static function dataPreSaveTransform() {
101 return array(
102 array( 'hello this is ~~~',
103 "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
104 ),
105 array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
106 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
107 ),
108 array( " Foo \n ",
109 " Foo",
110 ),
111 );
112 }
113
114 public static function dataPreloadTransform() {
115 return array(
116 array( 'hello this is ~~~',
117 'hello this is ~~~',
118 ),
119 array( 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
120 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
121 ),
122 );
123 }
124
125 public static function dataGetRedirectTarget() {
126 return array(
127 array( '#REDIRECT [[Test]]',
128 null,
129 ),
130 array( '#REDIRECT Test',
131 null,
132 ),
133 array( '* #REDIRECT [[Test]]',
134 null,
135 ),
136 );
137 }
138
139 /**
140 * @todo: test needs database!
141 */
142 /*
143 public function getRedirectChain() {
144 $text = $this->getNativeData();
145 return Title::newFromRedirectArray( $text );
146 }
147 */
148
149 /**
150 * @todo: test needs database!
151 */
152 /*
153 public function getUltimateRedirectTarget() {
154 $text = $this->getNativeData();
155 return Title::newFromRedirectRecurse( $text );
156 }
157 */
158
159 public static function dataIsCountable() {
160 return array(
161 array( '',
162 null,
163 'any',
164 true
165 ),
166 array( 'Foo',
167 null,
168 'any',
169 true
170 ),
171 array( 'Foo',
172 null,
173 'comma',
174 false
175 ),
176 array( 'Foo, bar',
177 null,
178 'comma',
179 false
180 ),
181 array( 'Foo',
182 null,
183 'link',
184 false
185 ),
186 array( 'Foo [[bar]]',
187 null,
188 'link',
189 false
190 ),
191 array( 'Foo',
192 true,
193 'link',
194 false
195 ),
196 array( 'Foo [[bar]]',
197 false,
198 'link',
199 false
200 ),
201 array( '#REDIRECT [[bar]]',
202 true,
203 'any',
204 true
205 ),
206 array( '#REDIRECT [[bar]]',
207 true,
208 'comma',
209 false
210 ),
211 array( '#REDIRECT [[bar]]',
212 true,
213 'link',
214 false
215 ),
216 );
217 }
218
219 public static function dataGetTextForSummary() {
220 return array(
221 array( "hello\nworld.",
222 16,
223 'hello world.',
224 ),
225 array( 'hello world.',
226 8,
227 'hello...',
228 ),
229 array( '[[hello world]].',
230 8,
231 '[[hel...',
232 ),
233 );
234 }
235
236 public function testMatchMagicWord( ) {
237 $mw = MagicWord::get( "staticredirect" );
238
239 $content = $this->newContent( "#REDIRECT [[FOO]]\n__STATICREDIRECT__" );
240 $this->assertFalse( $content->matchMagicWord( $mw ), "should not have matched magic word, since it's not wikitext" );
241 }
242
243 public function testUpdateRedirect( ) {
244 $target = Title::newFromText( "testUpdateRedirect_target" );
245
246 $content = $this->newContent( "#REDIRECT [[Someplace]]" );
247 $newContent = $content->updateRedirect( $target );
248
249 $this->assertTrue( $content->equals( $newContent ), "content should be unchanged since it's not wikitext" );
250 }
251
252 public function testGetModel() {
253 $content = $this->newContent( "hello world." );
254
255 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $content->getModel() );
256 }
257
258 public function testGetContentHandler() {
259 $content = $this->newContent( "hello world." );
260
261 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $content->getContentHandler()->getModelID() );
262 }
263
264 public static function dataEquals( ) {
265 return array(
266 array( new JavaScriptContent( "hallo" ), null, false ),
267 array( new JavaScriptContent( "hallo" ), new JavaScriptContent( "hallo" ), true ),
268 array( new JavaScriptContent( "hallo" ), new CssContent( "hallo" ), false ),
269 array( new JavaScriptContent( "hallo" ), new JavaScriptContent( "HALLO" ), false ),
270 );
271 }
272
273 }