mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 09:49:31 +02:00
Add linker tests, fix firstOnly behavior.
- Fix: The firstOnly option finally also works if a page contains a link to a given other page that was not currently added by the extension, i.e. that existed prior to an edit or that was manually added. Closes #12.
This commit is contained in:
@ -1,5 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* Unit tests for the LinkTitles\Linker class.
|
||||
*
|
||||
* The test class is prefixed with 'LinkTitles' to avoid a naming collision
|
||||
* with a class that exists in the MediaWiki core.
|
||||
*
|
||||
* Ideally the test classes should be namespaced, but when you do that, they
|
||||
* will no longer be automatically discovered.
|
||||
*
|
||||
* @group bovender
|
||||
* @group Database
|
||||
*/
|
||||
@ -17,12 +25,13 @@ class LinkTitlesLinkerTest extends LinkTitles\TestCase {
|
||||
public function testLinkContentSmartMode( $capitalLinks, $smartMode, $input, $expectedOutput) {
|
||||
$this->setMwGlobals( 'wgCapitalLinks', $capitalLinks );
|
||||
$config = new LinkTitles\Config();
|
||||
$config->firstOnly = false;
|
||||
$config->smartMode = $smartMode;
|
||||
$linker = new LinkTitles\Linker( $config );
|
||||
$this->assertSame( $expectedOutput, $linker->linkContent( $this->title, $input ));
|
||||
}
|
||||
|
||||
public static function provideLinkContentSmartModeData() {
|
||||
public function provideLinkContentSmartModeData() {
|
||||
return [
|
||||
[
|
||||
true, // wgCapitalLinks
|
||||
@ -86,4 +95,39 @@ class LinkTitlesLinkerTest extends LinkTitles\TestCase {
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideLinkContentFirstOnlyData
|
||||
*/
|
||||
public function testLinkContentFirstOnly( $firstOnly, $input, $expectedOutput ) {
|
||||
$config = new LinkTitles\Config();
|
||||
$config->firstOnly = $firstOnly;
|
||||
$linker = new LinkTitles\Linker( $config );
|
||||
$this->assertSame( $expectedOutput, $linker->linkContent( $this->title, $input ));
|
||||
}
|
||||
|
||||
public function provideLinkContentFirstOnlyData() {
|
||||
return [
|
||||
[
|
||||
false, // firstOnly
|
||||
'With firstOnly = false, link target is a link target multiple times',
|
||||
'With firstOnly = false, [[link target]] is a [[link target]] multiple times'
|
||||
],
|
||||
[
|
||||
false, // firstOnly
|
||||
'With firstOnly = false, [[link target]] is a link target multiple times',
|
||||
'With firstOnly = false, [[link target]] is a [[link target]] multiple times'
|
||||
],
|
||||
[
|
||||
true, // firstOnly
|
||||
'With firstOnly = true, link target is a link target only once',
|
||||
'With firstOnly = true, [[link target]] is a link target only once'
|
||||
],
|
||||
[
|
||||
true, // firstOnly
|
||||
'With firstOnly = true, [[link target]] is a link target only once',
|
||||
'With firstOnly = true, [[link target]] is a link target only once'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user