Replace __METHOD__ with __FUNCTION__
[lhc/web/wiklou.git] / tests / phpunit / includes / ExtraParserTest.php
1 <?php
2
3 /**
4 * Parser-related tests that don't suit for parserTests.txt
5 */
6 class ExtraParserTest extends PHPUnit_Framework_TestCase {
7
8 function setUp() {
9 global $wgMemc;
10 global $wgContLang;
11 global $wgShowDBErrorBacktrace;
12
13 $wgShowDBErrorBacktrace = true;
14 $wgContLang = new Language( 'en' );
15 $wgMemc = new FakeMemCachedClient;
16
17 $this->options = new ParserOptions;
18 $this->options->setTemplateCallback( array( __CLASS__, 'statelessFetchTemplate' ) );
19 $this->parser = new Parser;
20 }
21
22 // Bug 8689 - Long numeric lines kill the parser
23 function testBug8689() {
24 global $wgLang;
25 global $wgUser;
26 $longLine = '1.' . str_repeat( '1234567890', 100000 ) . "\n";
27
28 if ( $wgLang === null ) $wgLang = new Language;
29
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() );
34 }
35
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() );
41 }
42
43 function testPreSaveTransform() {
44 global $wgUser;
45 $title = Title::newFromText( __FUNCTION__ );
46 $outputText = $this->parser->preSaveTransform( "Test\r\n{{subst:Foo}}\n{{Bar}}", $title, $wgUser, $this->options );
47
48 $this->assertEquals( "Test\nContent of ''Template:Foo''\n{{Bar}}", $outputText );
49 }
50
51 function testPreprocess() {
52 $title = Title::newFromText( __FUNCTION__ );
53 $outputText = $this->parser->preprocess( "Test\n{{Foo}}\n{{Bar}}" , $title, $this->options );
54
55 $this->assertEquals( "Test\nContent of ''Template:Foo''\nContent of ''Template:Bar''", $outputText );
56 }
57
58 /**
59 * cleanSig() makes all templates substs and removes tildes
60 */
61 function testCleanSig() {
62 $title = Title::newFromText( __FUNCTION__ );
63 $outputText = $this->parser->cleanSig( "{{Foo}} ~~~~" );
64
65 $this->assertEquals( "{{SUBST:Foo}} ", $outputText );
66 }
67
68 /**
69 * cleanSigInSig() just removes tildes
70 */
71 function testCleanSigInSig() {
72 $title = Title::newFromText( __FUNCTION__ );
73 $outputText = $this->parser->cleanSigInSig( "{{Foo}} ~~~~" );
74
75 $this->assertEquals( "{{Foo}} ", $outputText );
76 }
77
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 );
81
82 $this->assertEquals( "=== Heading 2 ===\nSection 2", $outputText2 );
83 $this->assertEquals( "== Heading 1 ==\nSection 1\n=== Heading 2 ===\nSection 2", $outputText1 );
84 }
85
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" );
88
89 $this->assertEquals( "Section 0\nNew section 1\n\n== Heading 3 ==\nSection 3", $outputText );
90 }
91
92 /**
93 * Templates and comments are not affected, but noinclude/onlyinclude is.
94 */
95 function testGetPreloadText() {
96 $title = Title::newFromText( __FUNCTION__ );
97 $outputText = $this->parser->getPreloadText( "{{Foo}}<noinclude> censored</noinclude> information <!-- is very secret -->", $title, $this->options );
98
99 $this->assertEquals( "{{Foo}} information <!-- is very secret -->", $outputText );
100 }
101
102 static function statelessFetchTemplate( $title, $parser=false ) {
103 $text = "Content of ''" . $title->getFullText() . "''";
104 $deps = array();
105
106 return array(
107 'text' => $text,
108 'finalTitle' => $title,
109 'deps' => $deps );
110 }
111 }