* upgrade patches for oracle 1.17->1.19
[mediawiki.git] / tests / phpunit / includes / ExtraParserTest.php
blob54f2915d5ce812480f6d7f6e6db23afdca3c4497
1 <?php
3 /**
4 * Parser-related tests that don't suit for parserTests.txt
5 */
6 class ExtraParserTest extends MediaWikiTestCase {
8 function setUp() {
9 global $wgMemc;
10 global $wgContLang;
11 global $wgShowDBErrorBacktrace;
12 global $wgLanguageCode;
14 $wgShowDBErrorBacktrace = true;
15 $wgLanguageCode = 'en';
16 $wgContLang = new Language( 'en' );
17 $wgMemc = new EmptyBagOStuff;
19 $this->options = new ParserOptions;
20 $this->options->setTemplateCallback( array( __CLASS__, 'statelessFetchTemplate' ) );
21 $this->parser = new Parser;
24 // Bug 8689 - Long numeric lines kill the parser
25 function testBug8689() {
26 global $wgLang;
27 global $wgUser;
28 $longLine = '1.' . str_repeat( '1234567890', 100000 ) . "\n";
30 if ( $wgLang === null ) $wgLang = new Language;
32 $t = Title::newFromText( 'Unit test' );
33 $options = ParserOptions::newFromUser( $wgUser );
34 $this->assertEquals( "<p>$longLine</p>",
35 $this->parser->parse( $longLine, $t, $options )->getText() );
38 /* Test the parser entry points */
39 function testParse() {
40 $title = Title::newFromText( __FUNCTION__ );
41 $parserOutput = $this->parser->parse( "Test\n{{Foo}}\n{{Bar}}" , $title, $this->options );
42 $this->assertEquals( "<p>Test\nContent of <i>Template:Foo</i>\nContent of <i>Template:Bar</i>\n</p>", $parserOutput->getText() );
45 function testPreSaveTransform() {
46 global $wgUser, $wgTitle;
47 $title = Title::newFromText( __FUNCTION__ );
48 $oldTitle = $wgTitle; $wgTitle = $title; # Used by transformMsg()
49 $outputText = $this->parser->preSaveTransform( "Test\r\n{{subst:Foo}}\n{{Bar}}", $title, $wgUser, $this->options );
51 $this->assertEquals( "Test\nContent of ''Template:Foo''\n{{Bar}}", $outputText );
52 $wgTitle = $oldTitle;
55 function testPreprocess() {
56 $title = Title::newFromText( __FUNCTION__ );
57 $outputText = $this->parser->preprocess( "Test\n{{Foo}}\n{{Bar}}" , $title, $this->options );
59 $this->assertEquals( "Test\nContent of ''Template:Foo''\nContent of ''Template:Bar''", $outputText );
62 /**
63 * cleanSig() makes all templates substs and removes tildes
65 function testCleanSig() {
66 $title = Title::newFromText( __FUNCTION__ );
67 $outputText = $this->parser->cleanSig( "{{Foo}} ~~~~" );
69 $this->assertEquals( "{{SUBST:Foo}} ", $outputText );
72 /**
73 * cleanSigInSig() just removes tildes
75 function testCleanSigInSig() {
76 $title = Title::newFromText( __FUNCTION__ );
77 $outputText = $this->parser->cleanSigInSig( "{{Foo}} ~~~~" );
79 $this->assertEquals( "{{Foo}} ", $outputText );
82 function testGetSection() {
83 $outputText2 = $this->parser->getSection( "Section 0\n== Heading 1 ==\nSection 1\n=== Heading 2 ===\nSection 2\n== Heading 3 ==\nSection 3\n", 2 );
84 $outputText1 = $this->parser->getSection( "Section 0\n== Heading 1 ==\nSection 1\n=== Heading 2 ===\nSection 2\n== Heading 3 ==\nSection 3\n", 1 );
86 $this->assertEquals( "=== Heading 2 ===\nSection 2", $outputText2 );
87 $this->assertEquals( "== Heading 1 ==\nSection 1\n=== Heading 2 ===\nSection 2", $outputText1 );
90 function testReplaceSection() {
91 $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" );
93 $this->assertEquals( "Section 0\nNew section 1\n\n== Heading 3 ==\nSection 3", $outputText );
96 /**
97 * Templates and comments are not affected, but noinclude/onlyinclude is.
99 function testGetPreloadText() {
100 $title = Title::newFromText( __FUNCTION__ );
101 $outputText = $this->parser->getPreloadText( "{{Foo}}<noinclude> censored</noinclude> information <!-- is very secret -->", $title, $this->options );
103 $this->assertEquals( "{{Foo}} information <!-- is very secret -->", $outputText );
106 static function statelessFetchTemplate( $title, $parser=false ) {
107 $text = "Content of ''" . $title->getFullText() . "''";
108 $deps = array();
110 return array(
111 'text' => $text,
112 'finalTitle' => $title,
113 'deps' => $deps );