4 * Parser-related tests that don't suit for parserTests.txt
6 class ExtraParserTest
extends PHPUnit_Framework_TestCase
{
11 global $wgShowDBErrorBacktrace;
13 $wgShowDBErrorBacktrace = true;
14 $wgContLang = new Language( 'en' );
15 $wgMemc = new FakeMemCachedClient
;
17 $this->options
= new ParserOptions
;
18 $this->options
->setTemplateCallback( array( __CLASS__
, 'statelessFetchTemplate' ) );
19 $this->parser
= new Parser
;
22 // Bug 8689 - Long numeric lines kill the parser
23 function testBug8689() {
26 $longLine = '1.' . str_repeat( '1234567890', 100000 ) . "\n";
28 if ( $wgLang === null ) $wgLang = new Language
;
30 $t = Title
::newFromText( 'Unit test' );
31 $options = ParserOptions
::newFromUser( $wgUser );
32 $this->assertEquals( "<p>$longLine</p>",
33 $this->parser
->parse( $longLine, $t, $options )->getText() );
36 /* Test the parser entry points */
37 function testParse() {
38 $title = Title
::newFromText( __FUNCTION__
);
39 $parserOutput = $this->parser
->parse( "Test\n{{Foo}}\n{{Bar}}" , $title, $this->options
);
40 $this->assertEquals( "<p>Test\nContent of <i>Template:Foo</i>\nContent of <i>Template:Bar</i>\n</p>", $parserOutput->getText() );
43 function testPreSaveTransform() {
45 $title = Title
::newFromText( __FUNCTION__
);
46 $outputText = $this->parser
->preSaveTransform( "Test\r\n{{subst:Foo}}\n{{Bar}}", $title, $wgUser, $this->options
);
48 $this->assertEquals( "Test\nContent of ''Template:Foo''\n{{Bar}}", $outputText );
51 function testPreprocess() {
52 $title = Title
::newFromText( __FUNCTION__
);
53 $outputText = $this->parser
->preprocess( "Test\n{{Foo}}\n{{Bar}}" , $title, $this->options
);
55 $this->assertEquals( "Test\nContent of ''Template:Foo''\nContent of ''Template:Bar''", $outputText );
59 * cleanSig() makes all templates substs and removes tildes
61 function testCleanSig() {
62 $title = Title
::newFromText( __FUNCTION__
);
63 $outputText = $this->parser
->cleanSig( "{{Foo}} ~~~~" );
65 $this->assertEquals( "{{SUBST:Foo}} ", $outputText );
69 * cleanSigInSig() just removes tildes
71 function testCleanSigInSig() {
72 $title = Title
::newFromText( __FUNCTION__
);
73 $outputText = $this->parser
->cleanSigInSig( "{{Foo}} ~~~~" );
75 $this->assertEquals( "{{Foo}} ", $outputText );
78 function testGetSection() {
79 $outputText2 = $this->parser
->getSection( "Section 0\n== Heading 1 ==\nSection 1\n=== Heading 2 ===\nSection 2\n== Heading 3 ==\nSection 3\n", 2 );
80 $outputText1 = $this->parser
->getSection( "Section 0\n== Heading 1 ==\nSection 1\n=== Heading 2 ===\nSection 2\n== Heading 3 ==\nSection 3\n", 1 );
82 $this->assertEquals( "=== Heading 2 ===\nSection 2", $outputText2 );
83 $this->assertEquals( "== Heading 1 ==\nSection 1\n=== Heading 2 ===\nSection 2", $outputText1 );
86 function testReplaceSection() {
87 $outputText = $this->parser
->replaceSection( "Section 0\n== Heading 1 ==\nSection 1\n=== Heading 2 ===\nSection 2\n== Heading 3 ==\nSection 3\n", 1, "New section 1" );
89 $this->assertEquals( "Section 0\nNew section 1\n\n== Heading 3 ==\nSection 3", $outputText );
93 * Templates and comments are not affected, but noinclude/onlyinclude is.
95 function testGetPreloadText() {
96 $title = Title
::newFromText( __FUNCTION__
);
97 $outputText = $this->parser
->getPreloadText( "{{Foo}}<noinclude> censored</noinclude> information <!-- is very secret -->", $title, $this->options
);
99 $this->assertEquals( "{{Foo}} information <!-- is very secret -->", $outputText );
102 static function statelessFetchTemplate( $title, $parser=false ) {
103 $text = "Content of ''" . $title->getFullText() . "''";
108 'finalTitle' => $title,