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