e10d7067b3b03575eee128e651a110854ff753ac
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>',
107 public function dataPreloadTransform() {
109 array( 'hello this is ~~~',
112 array( 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
113 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
118 public function dataGetRedirectTarget() {
120 array( '#REDIRECT [[Test]]',
123 array( '#REDIRECT Test',
126 array( '* #REDIRECT [[Test]]',
133 * @todo: test needs database!
136 public function getRedirectChain() {
137 $text = $this->getNativeData();
138 return Title::newFromRedirectArray( $text );
143 * @todo: test needs database!
146 public function getUltimateRedirectTarget() {
147 $text = $this->getNativeData();
148 return Title::newFromRedirectRecurse( $text );
153 public function dataIsCountable() {
180 array( 'Foo [[bar]]',
190 array( 'Foo [[bar]]',
195 array( '#REDIRECT [[bar]]',
200 array( '#REDIRECT [[bar]]',
205 array( '#REDIRECT [[bar]]',
213 public function dataGetTextForSummary() {
215 array( "hello\nworld.",
219 array( 'hello world.',
223 array( '[[hello world]].',
230 public function testMatchMagicWord( ) {
231 $mw = MagicWord
::get( "staticredirect" );
233 $content = $this->newContent( "#REDIRECT [[FOO]]\n__STATICREDIRECT__" );
234 $this->assertFalse( $content->matchMagicWord( $mw ), "should not have matched magic word, since it's not wikitext" );
237 public function testUpdateRedirect( ) {
238 $target = Title
::newFromText( "testUpdateRedirect_target" );
240 $content = $this->newContent( "#REDIRECT [[Someplace]]" );
241 $newContent = $content->updateRedirect( $target );
243 $this->assertTrue( $content->equals( $newContent ), "content should be unchanged since it's not wikitext" );
246 # =================================================================================================================
248 public function testGetModel() {
249 $content = $this->newContent( "hello world." );
251 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT
, $content->getModel() );
254 public function testGetContentHandler() {
255 $content = $this->newContent( "hello world." );
257 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT
, $content->getContentHandler()->getModelID() );
260 public function dataEquals( ) {
262 array( new JavascriptContent( "hallo" ), null, false ),
263 array( new JavascriptContent( "hallo" ), new JavascriptContent( "hallo" ), true ),
264 array( new JavascriptContent( "hallo" ), new CssContent( "hallo" ), false ),
265 array( new JavascriptContent( "hallo" ), new JavascriptContent( "HALLO" ), false ),