From 14f74d141ab5580688bfd46d2f74c026e43ed967 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Wed, 1 Apr 2015 06:11:44 +0200 Subject: Update to MediaWiki 1.24.2 --- tests/phpunit/includes/ExtraParserTest.php | 218 +++++++++++++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100644 tests/phpunit/includes/ExtraParserTest.php (limited to 'tests/phpunit/includes/ExtraParserTest.php') diff --git a/tests/phpunit/includes/ExtraParserTest.php b/tests/phpunit/includes/ExtraParserTest.php new file mode 100644 index 00000000..4a4130e0 --- /dev/null +++ b/tests/phpunit/includes/ExtraParserTest.php @@ -0,0 +1,218 @@ +setMwGlobals( array( + 'wgShowDBErrorBacktrace' => true, + 'wgLanguageCode' => 'en', + 'wgContLang' => $contLang, + 'wgLang' => Language::factory( 'en' ), + 'wgMemc' => new EmptyBagOStuff, + 'wgAlwaysUseTidy' => false, + 'wgCleanSignatures' => true, + ) ); + + $this->options = ParserOptions::newFromUserAndLang( new User, $contLang ); + $this->options->setTemplateCallback( array( __CLASS__, 'statelessFetchTemplate' ) ); + $this->parser = new Parser; + + MagicWord::clearCache(); + } + + /** + * @see Bug 8689 + * @covers Parser::parse + */ + public function testLongNumericLinesDontKillTheParser() { + $longLine = '1.' . str_repeat( '1234567890', 100000 ) . "\n"; + + $title = Title::newFromText( 'Unit test' ); + $options = ParserOptions::newFromUser( new User() ); + $this->assertEquals( "

$longLine

", + $this->parser->parse( $longLine, $title, $options )->getText() ); + } + + /** + * Test the parser entry points + * @covers Parser::parse + */ + public function testParse() { + $title = Title::newFromText( __FUNCTION__ ); + $parserOutput = $this->parser->parse( "Test\n{{Foo}}\n{{Bar}}", $title, $this->options ); + $this->assertEquals( + "

Test\nContent of Template:Foo\nContent of Template:Bar\n

", + $parserOutput->getText() + ); + } + + /** + * @covers Parser::preSaveTransform + */ + public function testPreSaveTransform() { + $title = Title::newFromText( __FUNCTION__ ); + $outputText = $this->parser->preSaveTransform( + "Test\r\n{{subst:Foo}}\n{{Bar}}", + $title, + new User(), + $this->options + ); + + $this->assertEquals( "Test\nContent of ''Template:Foo''\n{{Bar}}", $outputText ); + } + + /** + * @covers Parser::preprocess + */ + public function testPreprocess() { + $title = Title::newFromText( __FUNCTION__ ); + $outputText = $this->parser->preprocess( "Test\n{{Foo}}\n{{Bar}}", $title, $this->options ); + + $this->assertEquals( + "Test\nContent of ''Template:Foo''\nContent of ''Template:Bar''", + $outputText + ); + } + + /** + * cleanSig() makes all templates substs and removes tildes + * @covers Parser::cleanSig + */ + public function testCleanSig() { + $title = Title::newFromText( __FUNCTION__ ); + $outputText = $this->parser->cleanSig( "{{Foo}} ~~~~" ); + + $this->assertEquals( "{{SUBST:Foo}} ", $outputText ); + } + + /** + * cleanSig() should do nothing if disabled + * @covers Parser::cleanSig + */ + public function testCleanSigDisabled() { + $this->setMwGlobals( 'wgCleanSignatures', false ); + + $title = Title::newFromText( __FUNCTION__ ); + $outputText = $this->parser->cleanSig( "{{Foo}} ~~~~" ); + + $this->assertEquals( "{{Foo}} ~~~~", $outputText ); + } + + /** + * cleanSigInSig() just removes tildes + * @dataProvider provideStringsForCleanSigInSig + * @covers Parser::cleanSigInSig + */ + public function testCleanSigInSig( $in, $out ) { + $this->assertEquals( Parser::cleanSigInSig( $in ), $out ); + } + + public static function provideStringsForCleanSigInSig() { + return array( + array( "{{Foo}} ~~~~", "{{Foo}} " ), + array( "~~~", "" ), + array( "~~~~~", "" ), + ); + } + + /** + * @covers Parser::getSection + */ + public function testGetSection() { + $outputText2 = $this->parser->getSection( + "Section 0\n== Heading 1 ==\nSection 1\n=== Heading 2 ===\n" + . "Section 2\n== Heading 3 ==\nSection 3\n", + 2 + ); + $outputText1 = $this->parser->getSection( + "Section 0\n== Heading 1 ==\nSection 1\n=== Heading 2 ===\n" + . "Section 2\n== Heading 3 ==\nSection 3\n", + 1 + ); + + $this->assertEquals( "=== Heading 2 ===\nSection 2", $outputText2 ); + $this->assertEquals( "== Heading 1 ==\nSection 1\n=== Heading 2 ===\nSection 2", $outputText1 ); + } + + /** + * @covers Parser::replaceSection + */ + public function testReplaceSection() { + $outputText = $this->parser->replaceSection( + "Section 0\n== Heading 1 ==\nSection 1\n=== Heading 2 ===\n" + . "Section 2\n== Heading 3 ==\nSection 3\n", + 1, + "New section 1" + ); + + $this->assertEquals( "Section 0\nNew section 1\n\n== Heading 3 ==\nSection 3", $outputText ); + } + + /** + * Templates and comments are not affected, but noinclude/onlyinclude is. + * @covers Parser::getPreloadText + */ + public function testGetPreloadText() { + $title = Title::newFromText( __FUNCTION__ ); + $outputText = $this->parser->getPreloadText( + "{{Foo}} censored information ", + $title, + $this->options + ); + + $this->assertEquals( "{{Foo}} information ", $outputText ); + } + + /** + * @param Title $title + * @param bool $parser + * + * @return array + */ + static function statelessFetchTemplate( $title, $parser = false ) { + $text = "Content of ''" . $title->getFullText() . "''"; + $deps = array(); + + return array( + 'text' => $text, + 'finalTitle' => $title, + 'deps' => $deps ); + } + + /** + * @group Database + * @covers Parser::parse + */ + public function testTrackingCategory() { + $title = Title::newFromText( __FUNCTION__ ); + $catName = wfMessage( 'broken-file-category' )->inContentLanguage()->text(); + $cat = Title::makeTitleSafe( NS_CATEGORY, $catName ); + $expected = array( $cat->getDBkey() ); + $parserOutput = $this->parser->parse( "[[file:nonexistent]]", $title, $this->options ); + $result = $parserOutput->getCategoryLinks(); + $this->assertEquals( $expected, $result ); + } + + /** + * @group Database + * @covers Parser::parse + */ + public function testTrackingCategorySpecial() { + // Special pages shouldn't have tracking cats. + $title = SpecialPage::getTitleFor( 'Contributions' ); + $parserOutput = $this->parser->parse( "[[file:nonexistent]]", $title, $this->options ); + $result = $parserOutput->getCategoryLinks(); + $this->assertEmpty( $result ); + } +} -- cgit v1.2.3-54-g00ecf