Merge branch 'Wikidata' into master.
[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 WikitextContentTest {
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>\n"),
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 /*
85 public function dataPreSaveTransform() {
86 return array(
87 array( 'hello this is ~~~',
88 "hello this is ~~~",
89 ),
90 array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
91 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
92 ),
93 );
94 }
95 */
96
97 public function dataPreloadTransform() {
98 return array(
99 array( 'hello this is ~~~',
100 "hello this is ~~~",
101 ),
102 array( 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
103 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
104 ),
105 );
106 }
107
108 public function dataGetRedirectTarget() {
109 return array(
110 array( '#REDIRECT [[Test]]',
111 null,
112 ),
113 array( '#REDIRECT Test',
114 null,
115 ),
116 array( '* #REDIRECT [[Test]]',
117 null,
118 ),
119 );
120 }
121
122 /**
123 * @todo: test needs database!
124 */
125 /*
126 public function getRedirectChain() {
127 $text = $this->getNativeData();
128 return Title::newFromRedirectArray( $text );
129 }
130 */
131
132 /**
133 * @todo: test needs database!
134 */
135 /*
136 public function getUltimateRedirectTarget() {
137 $text = $this->getNativeData();
138 return Title::newFromRedirectRecurse( $text );
139 }
140 */
141
142
143 public function dataIsCountable() {
144 return array(
145 array( '',
146 null,
147 'any',
148 true
149 ),
150 array( 'Foo',
151 null,
152 'any',
153 true
154 ),
155 array( 'Foo',
156 null,
157 'comma',
158 false
159 ),
160 array( 'Foo, bar',
161 null,
162 'comma',
163 false
164 ),
165 array( 'Foo',
166 null,
167 'link',
168 false
169 ),
170 array( 'Foo [[bar]]',
171 null,
172 'link',
173 false
174 ),
175 array( 'Foo',
176 true,
177 'link',
178 false
179 ),
180 array( 'Foo [[bar]]',
181 false,
182 'link',
183 false
184 ),
185 array( '#REDIRECT [[bar]]',
186 true,
187 'any',
188 true
189 ),
190 array( '#REDIRECT [[bar]]',
191 true,
192 'comma',
193 false
194 ),
195 array( '#REDIRECT [[bar]]',
196 true,
197 'link',
198 false
199 ),
200 );
201 }
202
203 public function dataGetTextForSummary() {
204 return array(
205 array( "hello\nworld.",
206 16,
207 'hello world.',
208 ),
209 array( 'hello world.',
210 8,
211 'hello...',
212 ),
213 array( '[[hello world]].',
214 8,
215 '[[hel...',
216 ),
217 );
218 }
219
220 public function testMatchMagicWord( ) {
221 $mw = MagicWord::get( "staticredirect" );
222
223 $content = $this->newContent( "#REDIRECT [[FOO]]\n__STATICREDIRECT__" );
224 $this->assertFalse( $content->matchMagicWord( $mw ), "should not have matched magic word, since it's not wikitext" );
225 }
226
227 public function testUpdateRedirect( ) {
228 $target = Title::newFromText( "testUpdateRedirect_target" );
229
230 $content = $this->newContent( "#REDIRECT [[Someplace]]" );
231 $newContent = $content->updateRedirect( $target );
232
233 $this->assertTrue( $content->equals( $newContent ), "content should be unchanged since it's not wikitext" );
234 }
235
236 # =================================================================================================================
237
238 public function testGetModel() {
239 $content = $this->newContent( "hello world." );
240
241 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $content->getModel() );
242 }
243
244 public function testGetContentHandler() {
245 $content = $this->newContent( "hello world." );
246
247 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $content->getContentHandler()->getModelID() );
248 }
249
250 public function dataEquals( ) {
251 return array(
252 array( new JavascriptContent( "hallo" ), null, false ),
253 array( new JavascriptContent( "hallo" ), new JavascriptContent( "hallo" ), true ),
254 array( new JavascriptContent( "hallo" ), new CssContent( "hallo" ), false ),
255 array( new JavascriptContent( "hallo" ), new JavascriptContent( "HALLO" ), false ),
256 );
257 }
258
259 }