diff --git a/tests/phpunit/ParseOnEditTest.php b/tests/phpunit/ExtensionTest.php similarity index 94% rename from tests/phpunit/ParseOnEditTest.php rename to tests/phpunit/ExtensionTest.php index 817ddfa..00b8ed8 100644 --- a/tests/phpunit/ParseOnEditTest.php +++ b/tests/phpunit/ExtensionTest.php @@ -3,7 +3,7 @@ * @group bovender * @group Database */ -class ParseOnEditTest extends LinkTitles\TestCase { +class ExtensionTest extends LinkTitles\TestCase { public function testParseOnEdit() { $this->setMwGlobals( [ diff --git a/tests/phpunit/LinkerTest.php b/tests/phpunit/LinkerTest.php new file mode 100644 index 0000000..b47a86f --- /dev/null +++ b/tests/phpunit/LinkerTest.php @@ -0,0 +1,89 @@ +title = $this->insertPage( 'source page', 'This page is the test page' )['title']; + parent::setUp(); // call last to have the Targets object invalidated after inserting the page + } + + /** + * @dataProvider provideLinkContentSmartModeData + */ + public function testLinkContentSmartMode( $capitalLinks, $smartMode, $input, $expectedOutput) { + $this->setMwGlobals( 'wgCapitalLinks', $capitalLinks ); + $config = new LinkTitles\Config(); + $config->smartMode = $smartMode; + $linker = new LinkTitles\Linker( $config ); + $this->assertSame( $expectedOutput, $linker->linkContent( $this->title, $input )); + } + + public static function provideLinkContentSmartModeData() { + return [ + [ + true, // wgCapitalLinks + true, // smartMode + 'With smart mode on and $wgCapitalLinks = true, this page should link to link target', + 'With smart mode on and $wgCapitalLinks = true, this page should link to [[link target]]' + ], + [ + true, // wgCapitalLinks + false, // smartMode + 'With smart mode off and $wgCapitalLinks = true, this page should link to link target', + 'With smart mode off and $wgCapitalLinks = true, this page should link to [[link target]]' + ], + [ + true, // wgCapitalLinks + true, // smartMode + 'With smart mode on and $wgCapitalLinks = true, this page should link to Link Target', + 'With smart mode on and $wgCapitalLinks = true, this page should link to [[Link target|Link Target]]' + ], + [ + true, // wgCapitalLinks + false, // smartMode + 'With smart mode off and $wgCapitalLinks = true, this page should not link to Link Target', + 'With smart mode off and $wgCapitalLinks = true, this page should not link to Link Target' + ], + [ + false, // wgCapitalLinks + true, // smartMode + 'With smart mode on and $wgCapitalLinks = false, this page should link to Link target', + 'With smart mode on and $wgCapitalLinks = false, this page should link to [[Link target]]' + ], + [ + false, // wgCapitalLinks + true, // smartMode + 'With smart mode on and $wgCapitalLinks = false, this page should link to link target', + 'With smart mode on and $wgCapitalLinks = false, this page should link to [[Link target|link target]]' + ], + [ + false, // wgCapitalLinks + false, // smartMode + 'With smart mode off and $wgCapitalLinks = false, this page should not link to link target', + 'With smart mode off and $wgCapitalLinks = false, this page should not link to link target' + ], + [ + false, // wgCapitalLinks + false, // smartMode + 'With smart mode off and $wgCapitalLinks = false, this page should not link to Link target', + 'With smart mode off and $wgCapitalLinks = false, this page should not link to [[Link target]]' + ], + [ + false, // wgCapitalLinks + true, // smartMode + 'With smart mode on and $wgCapitalLinks = false, this page should link to Link Target', + 'With smart mode on and $wgCapitalLinks = false, this page should link to [[Link target|Link Target]]' + ], + [ + false, // wgCapitalLinks + false, // smartMode + 'With smart mode off and $wgCapitalLinks = false, this page should not link to Link Target', + 'With smart mode off and $wgCapitalLinks = false, this page should not link to Link Target' + ], + ]; + } +}