b45caa2991c12587ace2cd7cc713dc8b07174407
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() {
18 array("MediaWiki:Test.js", null, "hello <world>\n",
19 "<pre class=\"mw-code mw-js\" dir=\"ltr\">\nhello <world>\n\n</pre>"),
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.
84 public function dataPreSaveTransform() {
86 array( 'hello this is ~~~',
87 "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
89 array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
90 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
95 public function dataPreloadTransform() {
97 array( 'hello this is ~~~',
100 array( 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
101 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
106 public function dataGetRedirectTarget() {
108 array( '#REDIRECT [[Test]]',
111 array( '#REDIRECT Test',
114 array( '* #REDIRECT [[Test]]',
121 * @todo: test needs database!
124 public function getRedirectChain() {
125 $text = $this->getNativeData();
126 return Title::newFromRedirectArray( $text );
131 * @todo: test needs database!
134 public function getUltimateRedirectTarget() {
135 $text = $this->getNativeData();
136 return Title::newFromRedirectRecurse( $text );
141 public function dataIsCountable() {
168 array( 'Foo [[bar]]',
178 array( 'Foo [[bar]]',
183 array( '#REDIRECT [[bar]]',
188 array( '#REDIRECT [[bar]]',
193 array( '#REDIRECT [[bar]]',
201 public function dataGetTextForSummary() {
203 array( "hello\nworld.",
207 array( 'hello world.',
211 array( '[[hello world]].',
218 public function testMatchMagicWord( ) {
219 $mw = MagicWord
::get( "staticredirect" );
221 $content = $this->newContent( "#REDIRECT [[FOO]]\n__STATICREDIRECT__" );
222 $this->assertFalse( $content->matchMagicWord( $mw ), "should not have matched magic word, since it's not wikitext" );
225 public function testUpdateRedirect( ) {
226 $target = Title
::newFromText( "testUpdateRedirect_target" );
228 $content = $this->newContent( "#REDIRECT [[Someplace]]" );
229 $newContent = $content->updateRedirect( $target );
231 $this->assertTrue( $content->equals( $newContent ), "content should be unchanged since it's not wikitext" );
234 # =================================================================================================================
236 public function testGetModel() {
237 $content = $this->newContent( "hello world." );
239 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT
, $content->getModel() );
242 public function testGetContentHandler() {
243 $content = $this->newContent( "hello world." );
245 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT
, $content->getContentHandler()->getModelID() );
248 public function dataEquals( ) {
250 array( new JavascriptContent( "hallo" ), null, false ),
251 array( new JavascriptContent( "hallo" ), new JavascriptContent( "hallo" ), true ),
252 array( new JavascriptContent( "hallo" ), new CssContent( "hallo" ), false ),
253 array( new JavascriptContent( "hallo" ), new JavascriptContent( "HALLO" ), false ),