MediaWiki
REL1_21
|
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 00092 public function testAddSectionHeader() { 00093 $content = $this->newContent( 'hello world' ); 00094 $c = $content->addSectionHeader( 'test' ); 00095 00096 $this->assertTrue( $content->equals( $c ) ); 00097 } 00098 00099 // XXX: currently, preSaveTransform is applied to scripts. this may change or become optional. 00100 public static function dataPreSaveTransform() { 00101 return array( 00102 array( 'hello this is ~~~', 00103 "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]", 00104 ), 00105 array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>', 00106 'hello \'\'this\'\' is <nowiki>~~~</nowiki>', 00107 ), 00108 array( " Foo \n ", 00109 " Foo", 00110 ), 00111 ); 00112 } 00113 00114 public static function dataPreloadTransform() { 00115 return array( 00116 array( 'hello this is ~~~', 00117 'hello this is ~~~', 00118 ), 00119 array( 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>', 00120 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>', 00121 ), 00122 ); 00123 } 00124 00125 public static function dataGetRedirectTarget() { 00126 return array( 00127 array( '#REDIRECT [[Test]]', 00128 null, 00129 ), 00130 array( '#REDIRECT Test', 00131 null, 00132 ), 00133 array( '* #REDIRECT [[Test]]', 00134 null, 00135 ), 00136 ); 00137 } 00138 00142 /* 00143 public function getRedirectChain() { 00144 $text = $this->getNativeData(); 00145 return Title::newFromRedirectArray( $text ); 00146 } 00147 */ 00148 00152 /* 00153 public function getUltimateRedirectTarget() { 00154 $text = $this->getNativeData(); 00155 return Title::newFromRedirectRecurse( $text ); 00156 } 00157 */ 00158 00159 public static function dataIsCountable() { 00160 return array( 00161 array( '', 00162 null, 00163 'any', 00164 true 00165 ), 00166 array( 'Foo', 00167 null, 00168 'any', 00169 true 00170 ), 00171 array( 'Foo', 00172 null, 00173 'comma', 00174 false 00175 ), 00176 array( 'Foo, bar', 00177 null, 00178 'comma', 00179 false 00180 ), 00181 array( 'Foo', 00182 null, 00183 'link', 00184 false 00185 ), 00186 array( 'Foo [[bar]]', 00187 null, 00188 'link', 00189 false 00190 ), 00191 array( 'Foo', 00192 true, 00193 'link', 00194 false 00195 ), 00196 array( 'Foo [[bar]]', 00197 false, 00198 'link', 00199 false 00200 ), 00201 array( '#REDIRECT [[bar]]', 00202 true, 00203 'any', 00204 true 00205 ), 00206 array( '#REDIRECT [[bar]]', 00207 true, 00208 'comma', 00209 false 00210 ), 00211 array( '#REDIRECT [[bar]]', 00212 true, 00213 'link', 00214 false 00215 ), 00216 ); 00217 } 00218 00219 public static function dataGetTextForSummary() { 00220 return array( 00221 array( "hello\nworld.", 00222 16, 00223 'hello world.', 00224 ), 00225 array( 'hello world.', 00226 8, 00227 'hello...', 00228 ), 00229 array( '[[hello world]].', 00230 8, 00231 '[[hel...', 00232 ), 00233 ); 00234 } 00235 00236 public function testMatchMagicWord() { 00237 $mw = MagicWord::get( "staticredirect" ); 00238 00239 $content = $this->newContent( "#REDIRECT [[FOO]]\n__STATICREDIRECT__" ); 00240 $this->assertFalse( $content->matchMagicWord( $mw ), "should not have matched magic word, since it's not wikitext" ); 00241 } 00242 00243 public function testUpdateRedirect() { 00244 $target = Title::newFromText( "testUpdateRedirect_target" ); 00245 00246 $content = $this->newContent( "#REDIRECT [[Someplace]]" ); 00247 $newContent = $content->updateRedirect( $target ); 00248 00249 $this->assertTrue( $content->equals( $newContent ), "content should be unchanged since it's not wikitext" ); 00250 } 00251 00252 public function testGetModel() { 00253 $content = $this->newContent( "hello world." ); 00254 00255 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $content->getModel() ); 00256 } 00257 00258 public function testGetContentHandler() { 00259 $content = $this->newContent( "hello world." ); 00260 00261 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $content->getContentHandler()->getModelID() ); 00262 } 00263 00264 public static function dataEquals() { 00265 return array( 00266 array( new JavaScriptContent( "hallo" ), null, false ), 00267 array( new JavaScriptContent( "hallo" ), new JavaScriptContent( "hallo" ), true ), 00268 array( new JavaScriptContent( "hallo" ), new CssContent( "hallo" ), false ), 00269 array( new JavaScriptContent( "hallo" ), new JavaScriptContent( "HALLO" ), false ), 00270 ); 00271 } 00272 00273 }