4 * @group ContentHandler
7 * ^--- needed, because we do need the database to test link updates
9 class JavascriptContentTest
extends WikitextContentTest
{
11 public function newContent( $text ) {
12 return new JavascriptContent( $text );
16 public function dataGetParserOutput() {
18 array("MediaWiki:Test.js", null, "hello <world>\n",
19 "<pre class=\"mw-code mw-js\" dir=\"ltr\">\nhello <world>\n\n</pre>\n"),
24 public function dataGetSection() {
26 array( WikitextContentTest
::$sections,
30 array( WikitextContentTest
::$sections,
34 array( WikitextContentTest
::$sections,
41 public function dataReplaceSection() {
43 array( WikitextContentTest
::$sections,
49 array( WikitextContentTest
::$sections,
55 array( WikitextContentTest
::$sections,
57 "== TEST ==\nmore fun",
61 array( WikitextContentTest
::$sections,
67 array( WikitextContentTest
::$sections,
76 public function testAddSectionHeader( ) {
77 $content = $this->newContent( 'hello world' );
78 $c = $content->addSectionHeader( 'test' );
80 $this->assertTrue( $content->equals( $c ) );
83 // XXX: currently, preSaveTransform is applied to scripts. this may change or become optional.
85 public function dataPreSaveTransform() {
87 array( 'hello this is ~~~',
90 array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
91 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
97 public function dataPreloadTransform() {
99 array( 'hello this is ~~~',
102 array( 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
103 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
108 public function dataGetRedirectTarget() {
110 array( '#REDIRECT [[Test]]',
113 array( '#REDIRECT Test',
116 array( '* #REDIRECT [[Test]]',
123 * @todo: test needs database!
126 public function getRedirectChain() {
127 $text = $this->getNativeData();
128 return Title::newFromRedirectArray( $text );
133 * @todo: test needs database!
136 public function getUltimateRedirectTarget() {
137 $text = $this->getNativeData();
138 return Title::newFromRedirectRecurse( $text );
143 public function dataIsCountable() {
170 array( 'Foo [[bar]]',
180 array( 'Foo [[bar]]',
185 array( '#REDIRECT [[bar]]',
190 array( '#REDIRECT [[bar]]',
195 array( '#REDIRECT [[bar]]',
203 public function dataGetTextForSummary() {
205 array( "hello\nworld.",
209 array( 'hello world.',
213 array( '[[hello world]].',
220 public function testMatchMagicWord( ) {
221 $mw = MagicWord
::get( "staticredirect" );
223 $content = $this->newContent( "#REDIRECT [[FOO]]\n__STATICREDIRECT__" );
224 $this->assertFalse( $content->matchMagicWord( $mw ), "should not have matched magic word, since it's not wikitext" );
227 public function testUpdateRedirect( ) {
228 $target = Title
::newFromText( "testUpdateRedirect_target" );
230 $content = $this->newContent( "#REDIRECT [[Someplace]]" );
231 $newContent = $content->updateRedirect( $target );
233 $this->assertTrue( $content->equals( $newContent ), "content should be unchanged since it's not wikitext" );
236 # =================================================================================================================
238 public function testGetModel() {
239 $content = $this->newContent( "hello world." );
241 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT
, $content->getModel() );
244 public function testGetContentHandler() {
245 $content = $this->newContent( "hello world." );
247 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT
, $content->getContentHandler()->getModelID() );
250 public function dataEquals( ) {
252 array( new JavascriptContent( "hallo" ), null, false ),
253 array( new JavascriptContent( "hallo" ), new JavascriptContent( "hallo" ), true ),
254 array( new JavascriptContent( "hallo" ), new CssContent( "hallo" ), false ),
255 array( new JavascriptContent( "hallo" ), new JavascriptContent( "HALLO" ), false ),