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,
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() {
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>',
117 public static function dataPreloadTransform() {
119 array( '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() {
130 array( '#REDIRECT [[Test]]',
133 array( '#REDIRECT Test',
136 array( '* #REDIRECT [[Test]]',
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() {
189 array( 'Foo [[bar]]',
199 array( 'Foo [[bar]]',
204 array( '#REDIRECT [[bar]]',
209 array( '#REDIRECT [[bar]]',
214 array( '#REDIRECT [[bar]]',
222 public static function dataGetTextForSummary() {
224 array( "hello\nworld.",
228 array( 'hello world.',
232 array( '[[hello world]].',
240 * @covers JavaScriptContent::matchMagicWord
242 public function testMatchMagicWord() {
243 $mw = MagicWord
::get( "staticredirect" );
245 $content = $this->newContent( "#REDIRECT [[FOO]]\n__STATICREDIRECT__" );
247 $content->matchMagicWord( $mw ),
248 "should not have matched magic word, since it's not wikitext"
253 * @covers JavaScriptContent::updateRedirect
255 public function testUpdateRedirect() {
256 $target = Title
::newFromText( "testUpdateRedirect_target" );
258 $content = $this->newContent( "#REDIRECT [[Someplace]]" );
259 $newContent = $content->updateRedirect( $target );
262 $content->equals( $newContent ),
263 "content should be unchanged since it's not wikitext"
268 * @covers JavaScriptContent::getModel
270 public function testGetModel() {
271 $content = $this->newContent( "hello world." );
273 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT
, $content->getModel() );
277 * @covers JavaScriptContent::getContentHandler
279 public function testGetContentHandler() {
280 $content = $this->newContent( "hello world." );
282 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT
, $content->getContentHandler()->getModelID() );
285 public static function dataEquals() {
287 array( new JavaScriptContent( "hallo" ), null, false ),
288 array( new JavaScriptContent( "hallo" ), new JavaScriptContent( "hallo" ), true ),
289 array( new JavaScriptContent( "hallo" ), new CssContent( "hallo" ), false ),
290 array( new JavaScriptContent( "hallo" ), new JavaScriptContent( "HALLO" ), false ),