X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fcontent%2FWikitextContentTest.php;h=7becd6f434cf9f90adba82101ca8debd1fea10dc;hb=cb1f290d1e52465897300e68adf59048d1528b35;hp=bd4ae35d087fcb30f4db093a15ad6ad748a86633;hpb=9392d01c4e95be3c156ad594d8a8b6aa678daa7d;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/content/WikitextContentTest.php b/tests/phpunit/includes/content/WikitextContentTest.php index bd4ae35d08..7becd6f434 100644 --- a/tests/phpunit/includes/content/WikitextContentTest.php +++ b/tests/phpunit/includes/content/WikitextContentTest.php @@ -361,6 +361,52 @@ just a test" $this->assertEquals( CONTENT_MODEL_WIKITEXT, $content->getContentHandler()->getModelID() ); } + public function testRedirectParserOption() { + $title = Title::newFromText( 'testRedirectParserOption' ); + + // Set up hook and its reporting variables + $wikitext = null; + $redirectTarget = null; + $this->mergeMwGlobalArrayValue( 'wgHooks', array( + 'InternalParseBeforeLinks' => array( + function ( &$parser, &$text, &$stripState ) use ( &$wikitext, &$redirectTarget ) { + $wikitext = $text; + $redirectTarget = $parser->getOptions()->getRedirectTarget(); + } + ) + ) ); + + // Test with non-redirect page + $wikitext = false; + $redirectTarget = false; + $content = $this->newContent( 'hello world.' ); + $options = $content->getContentHandler()->makeParserOptions( 'canonical' ); + $options->setRedirectTarget( $title ); + $content->getParserOutput( $title, null, $options ); + $this->assertEquals( 'hello world.', $wikitext, + 'Wikitext passed to hook was not as expected' + ); + $this->assertEquals( null, $redirectTarget, 'Redirect seen in hook was not null' ); + $this->assertEquals( $title, $options->getRedirectTarget(), + 'ParserOptions\' redirectTarget was changed' + ); + + // Test with a redirect page + $wikitext = false; + $redirectTarget = false; + $content = $this->newContent( "#REDIRECT [[TestRedirectParserOption/redir]]\nhello redirect." ); + $options = $content->getContentHandler()->makeParserOptions( 'canonical' ); + $content->getParserOutput( $title, null, $options ); + $this->assertEquals( 'hello redirect.', $wikitext, 'Wikitext passed to hook was not as expected' ); + $this->assertNotEquals( null, $redirectTarget, 'Redirect seen in hook was null' ); + $this->assertEquals( 'TestRedirectParserOption/redir', $redirectTarget->getFullText(), + 'Redirect seen in hook was not the expected title' + ); + $this->assertEquals( null, $options->getRedirectTarget(), + 'ParserOptions\' redirectTarget was changed' + ); + } + public static function dataEquals() { return array( array( new WikitextContent( "hallo" ), null, false ),