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