MediaWiki
REL1_22
|
00001 <?php 00002 00008 class JavaScriptContentTest extends TextContentTest { 00009 00010 public function newContent( $text ) { 00011 return new JavaScriptContent( $text ); 00012 } 00013 00014 public static function dataGetParserOutput() { 00015 return array( 00016 array( 00017 'MediaWiki:Test.js', 00018 null, 00019 "hello <world>\n", 00020 "<pre class=\"mw-code mw-js\" dir=\"ltr\">\nhello <world>\n\n</pre>" 00021 ), 00022 array( 00023 'MediaWiki:Test.js', 00024 null, 00025 "hello(); // [[world]]\n", 00026 "<pre class=\"mw-code mw-js\" dir=\"ltr\">\nhello(); // [[world]]\n\n</pre>", 00027 array( 00028 'Links' => array( 00029 array( 'World' => 0 ) 00030 ) 00031 ) 00032 ), 00033 00034 // TODO: more...? 00035 ); 00036 } 00037 00038 // XXX: Unused function 00039 public static function dataGetSection() { 00040 return array( 00041 array( WikitextContentTest::$sections, 00042 '0', 00043 null 00044 ), 00045 array( WikitextContentTest::$sections, 00046 '2', 00047 null 00048 ), 00049 array( WikitextContentTest::$sections, 00050 '8', 00051 null 00052 ), 00053 ); 00054 } 00055 00056 // XXX: Unused function 00057 public static function dataReplaceSection() { 00058 return array( 00059 array( WikitextContentTest::$sections, 00060 '0', 00061 'No more', 00062 null, 00063 null 00064 ), 00065 array( WikitextContentTest::$sections, 00066 '', 00067 'No more', 00068 null, 00069 null 00070 ), 00071 array( WikitextContentTest::$sections, 00072 '2', 00073 "== TEST ==\nmore fun", 00074 null, 00075 null 00076 ), 00077 array( WikitextContentTest::$sections, 00078 '8', 00079 'No more', 00080 null, 00081 null 00082 ), 00083 array( WikitextContentTest::$sections, 00084 'new', 00085 'No more', 00086 'New', 00087 null 00088 ), 00089 ); 00090 } 00091 00095 public function testAddSectionHeader() { 00096 $content = $this->newContent( 'hello world' ); 00097 $c = $content->addSectionHeader( 'test' ); 00098 00099 $this->assertTrue( $content->equals( $c ) ); 00100 } 00101 00102 // XXX: currently, preSaveTransform is applied to scripts. this may change or become optional. 00103 public static function dataPreSaveTransform() { 00104 return array( 00105 array( 'hello this is ~~~', 00106 "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]", 00107 ), 00108 array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>', 00109 'hello \'\'this\'\' is <nowiki>~~~</nowiki>', 00110 ), 00111 array( " Foo \n ", 00112 " Foo", 00113 ), 00114 ); 00115 } 00116 00117 public static function dataPreloadTransform() { 00118 return array( 00119 array( 'hello this is ~~~', 00120 'hello this is ~~~', 00121 ), 00122 array( 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>', 00123 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>', 00124 ), 00125 ); 00126 } 00127 00128 public static function dataGetRedirectTarget() { 00129 return array( 00130 array( '#REDIRECT [[Test]]', 00131 null, 00132 ), 00133 array( '#REDIRECT Test', 00134 null, 00135 ), 00136 array( '* #REDIRECT [[Test]]', 00137 null, 00138 ), 00139 ); 00140 } 00141 00145 /* 00146 public function getRedirectChain() { 00147 $text = $this->getNativeData(); 00148 return Title::newFromRedirectArray( $text ); 00149 } 00150 */ 00151 00155 /* 00156 public function getUltimateRedirectTarget() { 00157 $text = $this->getNativeData(); 00158 return Title::newFromRedirectRecurse( $text ); 00159 } 00160 */ 00161 00162 public static function dataIsCountable() { 00163 return array( 00164 array( '', 00165 null, 00166 'any', 00167 true 00168 ), 00169 array( 'Foo', 00170 null, 00171 'any', 00172 true 00173 ), 00174 array( 'Foo', 00175 null, 00176 'comma', 00177 false 00178 ), 00179 array( 'Foo, bar', 00180 null, 00181 'comma', 00182 false 00183 ), 00184 array( 'Foo', 00185 null, 00186 'link', 00187 false 00188 ), 00189 array( 'Foo [[bar]]', 00190 null, 00191 'link', 00192 false 00193 ), 00194 array( 'Foo', 00195 true, 00196 'link', 00197 false 00198 ), 00199 array( 'Foo [[bar]]', 00200 false, 00201 'link', 00202 false 00203 ), 00204 array( '#REDIRECT [[bar]]', 00205 true, 00206 'any', 00207 true 00208 ), 00209 array( '#REDIRECT [[bar]]', 00210 true, 00211 'comma', 00212 false 00213 ), 00214 array( '#REDIRECT [[bar]]', 00215 true, 00216 'link', 00217 false 00218 ), 00219 ); 00220 } 00221 00222 public static function dataGetTextForSummary() { 00223 return array( 00224 array( "hello\nworld.", 00225 16, 00226 'hello world.', 00227 ), 00228 array( 'hello world.', 00229 8, 00230 'hello...', 00231 ), 00232 array( '[[hello world]].', 00233 8, 00234 '[[hel...', 00235 ), 00236 ); 00237 } 00238 00242 public function testMatchMagicWord() { 00243 $mw = MagicWord::get( "staticredirect" ); 00244 00245 $content = $this->newContent( "#REDIRECT [[FOO]]\n__STATICREDIRECT__" ); 00246 $this->assertFalse( $content->matchMagicWord( $mw ), "should not have matched magic word, since it's not wikitext" ); 00247 } 00248 00252 public function testUpdateRedirect() { 00253 $target = Title::newFromText( "testUpdateRedirect_target" ); 00254 00255 $content = $this->newContent( "#REDIRECT [[Someplace]]" ); 00256 $newContent = $content->updateRedirect( $target ); 00257 00258 $this->assertTrue( $content->equals( $newContent ), "content should be unchanged since it's not wikitext" ); 00259 } 00260 00264 public function testGetModel() { 00265 $content = $this->newContent( "hello world." ); 00266 00267 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $content->getModel() ); 00268 } 00269 00273 public function testGetContentHandler() { 00274 $content = $this->newContent( "hello world." ); 00275 00276 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $content->getContentHandler()->getModelID() ); 00277 } 00278 00279 public static function dataEquals() { 00280 return array( 00281 array( new JavaScriptContent( "hallo" ), null, false ), 00282 array( new JavaScriptContent( "hallo" ), new JavaScriptContent( "hallo" ), true ), 00283 array( new JavaScriptContent( "hallo" ), new CssContent( "hallo" ), false ), 00284 array( new JavaScriptContent( "hallo" ), new JavaScriptContent( "HALLO" ), false ), 00285 ); 00286 } 00287 }