4 * @group ContentHandler
6 * ^--- needed, because we do need the database to test link updates
8 class JavaScriptContentTest
extends TextContentTest
{
10 public function newContent( $text ) {
11 return new JavaScriptContent( $text );
14 public static function dataGetParserOutput() {
20 "<pre class=\"mw-code mw-js\" dir=\"ltr\">\nhello <world>\n\n</pre>"
25 "hello(); // [[world]]\n",
26 "<pre class=\"mw-code mw-js\" dir=\"ltr\">\nhello(); // [[world]]\n\n</pre>",
38 // XXX: Unused function
39 public static function dataGetSection() {
41 array( WikitextContentTest
::$sections,
45 array( WikitextContentTest
::$sections,
49 array( WikitextContentTest
::$sections,
56 // XXX: Unused function
57 public static function dataReplaceSection() {
59 array( WikitextContentTest
::$sections,
65 array( WikitextContentTest
::$sections,
71 array( WikitextContentTest
::$sections,
73 "== TEST ==\nmore fun",
77 array( WikitextContentTest
::$sections,
83 array( WikitextContentTest
::$sections,
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() {
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>',
114 public static function dataPreloadTransform() {
116 array( '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() {
127 array( '#REDIRECT [[Test]]',
130 array( '#REDIRECT Test',
133 array( '* #REDIRECT [[Test]]',
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() {
186 array( 'Foo [[bar]]',
196 array( 'Foo [[bar]]',
201 array( '#REDIRECT [[bar]]',
206 array( '#REDIRECT [[bar]]',
211 array( '#REDIRECT [[bar]]',
219 public static function dataGetTextForSummary() {
221 array( "hello\nworld.",
225 array( 'hello world.',
229 array( '[[hello world]].',
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() {
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 ),