Unit tests for parseOnRender.

This commit is contained in:
Daniel Kraus
2017-09-06 13:00:27 +02:00
parent 2fc921249f
commit c99ec87b87

View File

@ -26,23 +26,63 @@
*/ */
class ExtensionTest extends LinkTitles\TestCase { class ExtensionTest extends LinkTitles\TestCase {
public function testParseOnEdit() { /**
* @dataProvider provideParseOnEditData
*/
public function testParseOnEdit( $parseOnEdit, $input, $expectedOutput) {
$this->setMwGlobals( [ $this->setMwGlobals( [
'wgLinkTitlesParseOnEdit' => true, 'wgLinkTitlesParseOnEdit' => $parseOnEdit,
'wgLinkTitlesParseOnRender' => false 'wgLinkTitlesParseOnRender' => !$parseOnEdit
] ); ] );
$pageId = $this->insertPage( 'test page', 'This page should link to the link target but not to test page' )['id']; $pageId = $this->insertPage( 'test page', $input )['id'];
$page = WikiPage::newFromId( $pageId ); $page = WikiPage::newFromId( $pageId );
$this->assertSame( 'This page should link to the [[link target]] but not to test page', self::getPageText( $page ) ); $this->assertSame( $expectedOutput, self::getPageText( $page ) );
} }
public function testDoNotParseOnEdit() { public function provideParseOnEditData() {
return [
[
true, // parseOnEdit
'This page should link to the link target but not to test page',
'This page should link to the [[link target]] but not to test page'
],
[
false,
'This page should *not* link to the link target',
'This page should *not* link to the link target'
]
];
}
/**
* @dataProvider provideParseOnRenderData
*/
public function testParseOnRender( $parseOnRender, $input, $expectedOutput) {
$this->setMwGlobals( [ $this->setMwGlobals( [
'wgLinkTitlesParseOnEdit' => false, 'wgLinkTitlesParseOnEdit' => false, // do not modify the page as we create it
'wgLinkTitlesParseOnRender' => false 'wgLinkTitlesParseOnRender' => $parseOnRender
] ); ] );
$pageId = $this->insertPage( 'test page', 'This page should not link to the link target' )['id']; $title = $this->insertPage( 'test page', $input )['title'];
$page = WikiPage::newFromId( $pageId ); $page = new WikiPage( $title );
$this->assertSame( 'This page should not link to the link target', self::getPageText( $page ) ); $content = $page->getContent();
$output = $content->getParserOutput( $title, null, null, false );
$lines = explode( "\n", $output->getText() );
$this->assertRegexp( $expectedOutput, $lines[0] );
}
public function provideParseOnRenderData() {
return [
[
true, // parseOnRender
'This page should link to the link target but not to test page',
'_This page should link to the <a href=[^>]+>link target</a> but not to test page_'
],
[
false,
'This page should not link to the link target',
'_This page should not link to the link target_'
]
];
} }
} }