4 * @group ContentHandler
7 * ^--- needed, because we do need the database to test link updates
9 class JavascriptContentTest
extends TextContentTest
{
11 public function newContent( $text ) {
12 return new JavascriptContent( $text );
16 public function dataGetParserOutput() {
22 "<pre class=\"mw-code mw-js\" dir=\"ltr\">\nhello <world>\n\n</pre>" ),
27 "hello(); // [[world]]\n",
28 "<pre class=\"mw-code mw-js\" dir=\"ltr\">\nhello(); // [[world]]\n\n</pre>",
29 array( 'Links' => array( // NOTE: assumes default settings for $wgTextModelsToParse
30 array( 'World' => 0 ) ) ) ),
36 public function dataGetSection() {
38 array( WikitextContentTest
::$sections,
42 array( WikitextContentTest
::$sections,
46 array( WikitextContentTest
::$sections,
53 public function dataReplaceSection() {
55 array( WikitextContentTest
::$sections,
61 array( WikitextContentTest
::$sections,
67 array( WikitextContentTest
::$sections,
69 "== TEST ==\nmore fun",
73 array( WikitextContentTest
::$sections,
79 array( WikitextContentTest
::$sections,
88 public function testAddSectionHeader( ) {
89 $content = $this->newContent( 'hello world' );
90 $c = $content->addSectionHeader( 'test' );
92 $this->assertTrue( $content->equals( $c ) );
95 // XXX: currently, preSaveTransform is applied to scripts. this may change or become optional.
96 public function dataPreSaveTransform() {
98 array( 'hello this is ~~~',
99 "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
101 array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
102 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
110 public function dataPreloadTransform() {
112 array( 'hello this is ~~~',
115 array( 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
116 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
121 public function dataGetRedirectTarget() {
123 array( '#REDIRECT [[Test]]',
126 array( '#REDIRECT Test',
129 array( '* #REDIRECT [[Test]]',
136 * @todo: test needs database!
139 public function getRedirectChain() {
140 $text = $this->getNativeData();
141 return Title::newFromRedirectArray( $text );
146 * @todo: test needs database!
149 public function getUltimateRedirectTarget() {
150 $text = $this->getNativeData();
151 return Title::newFromRedirectRecurse( $text );
156 public function dataIsCountable() {
183 array( 'Foo [[bar]]',
193 array( 'Foo [[bar]]',
198 array( '#REDIRECT [[bar]]',
203 array( '#REDIRECT [[bar]]',
208 array( '#REDIRECT [[bar]]',
216 public function dataGetTextForSummary() {
218 array( "hello\nworld.",
222 array( 'hello world.',
226 array( '[[hello world]].',
233 public function testMatchMagicWord( ) {
234 $mw = MagicWord
::get( "staticredirect" );
236 $content = $this->newContent( "#REDIRECT [[FOO]]\n__STATICREDIRECT__" );
237 $this->assertFalse( $content->matchMagicWord( $mw ), "should not have matched magic word, since it's not wikitext" );
240 public function testUpdateRedirect( ) {
241 $target = Title
::newFromText( "testUpdateRedirect_target" );
243 $content = $this->newContent( "#REDIRECT [[Someplace]]" );
244 $newContent = $content->updateRedirect( $target );
246 $this->assertTrue( $content->equals( $newContent ), "content should be unchanged since it's not wikitext" );
249 # =================================================================================================================
251 public function testGetModel() {
252 $content = $this->newContent( "hello world." );
254 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT
, $content->getModel() );
257 public function testGetContentHandler() {
258 $content = $this->newContent( "hello world." );
260 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT
, $content->getContentHandler()->getModelID() );
263 public function dataEquals( ) {
265 array( new JavascriptContent( "hallo" ), null, false ),
266 array( new JavascriptContent( "hallo" ), new JavascriptContent( "hallo" ), true ),
267 array( new JavascriptContent( "hallo" ), new CssContent( "hallo" ), false ),
268 array( new JavascriptContent( "hallo" ), new JavascriptContent( "HALLO" ), false ),