4 * @group ContentHandler
6 class JavascriptContentTest
extends WikitextContentTest
{
8 public function newContent( $text ) {
9 return new JavascriptContent( $text );
13 public function dataGetParserOutput() {
15 array("MediaWiki:Test.js", "hello <world>\n",
16 "<pre class=\"mw-code mw-js\" dir=\"ltr\">\nhello <world>\n\n</pre>\n"),
21 public function dataGetSection() {
23 array( WikitextContentTest
::$sections,
27 array( WikitextContentTest
::$sections,
31 array( WikitextContentTest
::$sections,
38 public function dataReplaceSection() {
40 array( WikitextContentTest
::$sections,
46 array( WikitextContentTest
::$sections,
52 array( WikitextContentTest
::$sections,
54 "== TEST ==\nmore fun",
58 array( WikitextContentTest
::$sections,
64 array( WikitextContentTest
::$sections,
73 public function testAddSectionHeader( ) {
74 $content = $this->newContent( 'hello world' );
75 $c = $content->addSectionHeader( 'test' );
77 $this->assertTrue( $content->equals( $c ) );
80 // XXX: currently, preSaveTransform is applied to scripts. this may change or become optional.
82 public function dataPreSaveTransform() {
84 array( 'hello this is ~~~',
87 array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
88 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
94 public function dataPreloadTransform() {
96 array( 'hello this is ~~~',
99 array( 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
100 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
105 public function dataGetRedirectTarget() {
107 array( '#REDIRECT [[Test]]',
110 array( '#REDIRECT Test',
113 array( '* #REDIRECT [[Test]]',
120 * @todo: test needs database!
123 public function getRedirectChain() {
124 $text = $this->getNativeData();
125 return Title::newFromRedirectArray( $text );
130 * @todo: test needs database!
133 public function getUltimateRedirectTarget() {
134 $text = $this->getNativeData();
135 return Title::newFromRedirectRecurse( $text );
140 public function dataIsCountable() {
167 array( 'Foo [[bar]]',
177 array( 'Foo [[bar]]',
182 array( '#REDIRECT [[bar]]',
187 array( '#REDIRECT [[bar]]',
192 array( '#REDIRECT [[bar]]',
200 public function dataGetTextForSummary() {
202 array( "hello\nworld.",
206 array( 'hello world.',
210 array( '[[hello world]].',
217 public function testMatchMagicWord( ) {
218 $mw = MagicWord
::get( "staticredirect" );
220 $content = $this->newContent( "#REDIRECT [[FOO]]\n__STATICREDIRECT__" );
221 $this->assertFalse( $content->matchMagicWord( $mw ), "should not have matched magic word, since it's not wikitext" );
224 public function testUpdateRedirect( ) {
225 $target = Title
::newFromText( "testUpdateRedirect_target" );
227 $content = $this->newContent( "#REDIRECT [[Someplace]]" );
228 $newContent = $content->updateRedirect( $target );
230 $this->assertTrue( $content->equals( $newContent ), "content should be unchanged since it's not wikitext" );
233 # =================================================================================================================
235 public function testGetModel() {
236 $content = $this->newContent( "hello world." );
238 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT
, $content->getModel() );
241 public function testGetContentHandler() {
242 $content = $this->newContent( "hello world." );
244 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT
, $content->getContentHandler()->getModelID() );
247 public function dataEquals( ) {
249 array( new JavascriptContent( "hallo" ), null, false ),
250 array( new JavascriptContent( "hallo" ), new JavascriptContent( "hallo" ), true ),
251 array( new JavascriptContent( "hallo" ), new CssContent( "hallo" ), false ),
252 array( new JavascriptContent( "hallo" ), new JavascriptContent( "HALLO" ), false ),