Merge "Blacklist Google Glass web browser from JS"
[mediawiki.git] / tests / phpunit / includes / content / JavaScriptContentTest.php
blobc8616ff00631a3e38499b77c489a2ee3b946b8d0
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 /**
93 * @covers JavaScriptContent::addSectionHeader
95 public function testAddSectionHeader() {
96 $content = $this->newContent( 'hello world' );
97 $c = $content->addSectionHeader( 'test' );
99 $this->assertTrue( $content->equals( $c ) );
102 // XXX: currently, preSaveTransform is applied to scripts. this may change or become optional.
103 public static function dataPreSaveTransform() {
104 return array(
105 array( 'hello this is ~~~',
106 "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
108 array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
109 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
111 array( " Foo \n ",
112 " Foo",
117 public static function dataPreloadTransform() {
118 return array(
119 array( 'hello this is ~~~',
120 'hello this is ~~~',
122 array( 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
123 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
128 public static function dataGetRedirectTarget() {
129 return array(
130 array( '#REDIRECT [[Test]]',
131 null,
133 array( '#REDIRECT Test',
134 null,
136 array( '* #REDIRECT [[Test]]',
137 null,
143 * @todo Test needs database!
146 public function getRedirectChain() {
147 $text = $this->getNativeData();
148 return Title::newFromRedirectArray( $text );
153 * @todo Test needs database!
156 public function getUltimateRedirectTarget() {
157 $text = $this->getNativeData();
158 return Title::newFromRedirectRecurse( $text );
162 public static function dataIsCountable() {
163 return array(
164 array( '',
165 null,
166 'any',
167 true
169 array( 'Foo',
170 null,
171 'any',
172 true
174 array( 'Foo',
175 null,
176 'comma',
177 false
179 array( 'Foo, bar',
180 null,
181 'comma',
182 false
184 array( 'Foo',
185 null,
186 'link',
187 false
189 array( 'Foo [[bar]]',
190 null,
191 'link',
192 false
194 array( 'Foo',
195 true,
196 'link',
197 false
199 array( 'Foo [[bar]]',
200 false,
201 'link',
202 false
204 array( '#REDIRECT [[bar]]',
205 true,
206 'any',
207 true
209 array( '#REDIRECT [[bar]]',
210 true,
211 'comma',
212 false
214 array( '#REDIRECT [[bar]]',
215 true,
216 'link',
217 false
222 public static function dataGetTextForSummary() {
223 return array(
224 array( "hello\nworld.",
226 'hello world.',
228 array( 'hello world.',
230 'hello...',
232 array( '[[hello world]].',
234 '[[hel...',
240 * @covers JavaScriptContent::matchMagicWord
242 public function testMatchMagicWord() {
243 $mw = MagicWord::get( "staticredirect" );
245 $content = $this->newContent( "#REDIRECT [[FOO]]\n__STATICREDIRECT__" );
246 $this->assertFalse( $content->matchMagicWord( $mw ), "should not have matched magic word, since it's not wikitext" );
250 * @covers JavaScriptContent::updateRedirect
252 public function testUpdateRedirect() {
253 $target = Title::newFromText( "testUpdateRedirect_target" );
255 $content = $this->newContent( "#REDIRECT [[Someplace]]" );
256 $newContent = $content->updateRedirect( $target );
258 $this->assertTrue( $content->equals( $newContent ), "content should be unchanged since it's not wikitext" );
262 * @covers JavaScriptContent::getModel
264 public function testGetModel() {
265 $content = $this->newContent( "hello world." );
267 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $content->getModel() );
271 * @covers JavaScriptContent::getContentHandler
273 public function testGetContentHandler() {
274 $content = $this->newContent( "hello world." );
276 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $content->getContentHandler()->getModelID() );
279 public static function dataEquals() {
280 return array(
281 array( new JavaScriptContent( "hallo" ), null, false ),
282 array( new JavaScriptContent( "hallo" ), new JavaScriptContent( "hallo" ), true ),
283 array( new JavaScriptContent( "hallo" ), new CssContent( "hallo" ), false ),
284 array( new JavaScriptContent( "hallo" ), new JavaScriptContent( "HALLO" ), false ),