test: coverage recording now needs to be explicit
[mediawiki.git] / tests / phpunit / includes / content / JavaScriptContentTest.php
blob5c1ff8fb99709325549220c065d624daf499d930
1 <?php
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 {
10 public function newContent( $text ) {
11 return new JavaScriptContent( $text );
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>"
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 )
34 // TODO: more...?
38 // XXX: Unused function
39 public static function dataGetSection() {
40 return array(
41 array( WikitextContentTest::$sections,
42 '0',
43 null
45 array( WikitextContentTest::$sections,
46 '2',
47 null
49 array( WikitextContentTest::$sections,
50 '8',
51 null
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
65 array( WikitextContentTest::$sections,
66 '',
67 'No more',
68 null,
69 null
71 array( WikitextContentTest::$sections,
72 '2',
73 "== TEST ==\nmore fun",
74 null,
75 null
77 array( WikitextContentTest::$sections,
78 '8',
79 'No more',
80 null,
81 null
83 array( WikitextContentTest::$sections,
84 'new',
85 'No more',
86 'New',
87 null
92 public function testAddSectionHeader() {
93 $content = $this->newContent( 'hello world' );
94 $c = $content->addSectionHeader( 'test' );
96 $this->assertTrue( $content->equals( $c ) );
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]]",
105 array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
106 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
108 array( " Foo \n ",
109 " Foo",
114 public static function dataPreloadTransform() {
115 return array(
116 array( 'hello this is ~~~',
117 'hello this is ~~~',
119 array( 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
120 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
125 public static function dataGetRedirectTarget() {
126 return array(
127 array( '#REDIRECT [[Test]]',
128 null,
130 array( '#REDIRECT Test',
131 null,
133 array( '* #REDIRECT [[Test]]',
134 null,
140 * @todo Test needs database!
143 public function getRedirectChain() {
144 $text = $this->getNativeData();
145 return Title::newFromRedirectArray( $text );
150 * @todo Test needs database!
153 public function getUltimateRedirectTarget() {
154 $text = $this->getNativeData();
155 return Title::newFromRedirectRecurse( $text );
159 public static function dataIsCountable() {
160 return array(
161 array( '',
162 null,
163 'any',
164 true
166 array( 'Foo',
167 null,
168 'any',
169 true
171 array( 'Foo',
172 null,
173 'comma',
174 false
176 array( 'Foo, bar',
177 null,
178 'comma',
179 false
181 array( 'Foo',
182 null,
183 'link',
184 false
186 array( 'Foo [[bar]]',
187 null,
188 'link',
189 false
191 array( 'Foo',
192 true,
193 'link',
194 false
196 array( 'Foo [[bar]]',
197 false,
198 'link',
199 false
201 array( '#REDIRECT [[bar]]',
202 true,
203 'any',
204 true
206 array( '#REDIRECT [[bar]]',
207 true,
208 'comma',
209 false
211 array( '#REDIRECT [[bar]]',
212 true,
213 'link',
214 false
219 public static function dataGetTextForSummary() {
220 return array(
221 array( "hello\nworld.",
223 'hello world.',
225 array( 'hello world.',
227 'hello...',
229 array( '[[hello world]].',
231 '[[hel...',
236 public function testMatchMagicWord() {
237 $mw = MagicWord::get( "staticredirect" );
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" );
243 public function testUpdateRedirect() {
244 $target = Title::newFromText( "testUpdateRedirect_target" );
246 $content = $this->newContent( "#REDIRECT [[Someplace]]" );
247 $newContent = $content->updateRedirect( $target );
249 $this->assertTrue( $content->equals( $newContent ), "content should be unchanged since it's not wikitext" );
252 public function testGetModel() {
253 $content = $this->newContent( "hello world." );
255 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $content->getModel() );
258 public function testGetContentHandler() {
259 $content = $this->newContent( "hello world." );
261 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $content->getContentHandler()->getModelID() );
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 ),