mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 09:49:31 +02:00
Add Target unit test.
This commit is contained in:
@ -28,10 +28,17 @@ namespace LinkTitles;
|
|||||||
*/
|
*/
|
||||||
class Target {
|
class Target {
|
||||||
/**
|
/**
|
||||||
* \TitleValue object for the current target page title.
|
* A Title object for the target page currently being examined.
|
||||||
* @var \TitleValue $titleValue;
|
* @var \Title $title
|
||||||
*/
|
*/
|
||||||
public $titleValue;
|
private $title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Caches the target page content as a \Content object.
|
||||||
|
*
|
||||||
|
* @var \Content $content
|
||||||
|
*/
|
||||||
|
private $content;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Regex that matches the start of a word; this expression depends on the
|
* Regex that matches the start of a word; this expression depends on the
|
||||||
@ -47,19 +54,6 @@ class Target {
|
|||||||
*/
|
*/
|
||||||
public $wordEnd;
|
public $wordEnd;
|
||||||
|
|
||||||
/**
|
|
||||||
* A Title object for the target page currently being examined.
|
|
||||||
* @var \Title $title
|
|
||||||
*/
|
|
||||||
private $title;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Caches the target page content as a \Content object.
|
|
||||||
*
|
|
||||||
* @var \Content $content
|
|
||||||
*/
|
|
||||||
private $content;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LinkTitles configuration.
|
* LinkTitles configuration.
|
||||||
* @var Config $config
|
* @var Config $config
|
||||||
@ -74,7 +68,7 @@ class Target {
|
|||||||
* @param Int $nameSpace Name space of the target page
|
* @param Int $nameSpace Name space of the target page
|
||||||
* @param String &$title Title of the target page
|
* @param String &$title Title of the target page
|
||||||
*/
|
*/
|
||||||
public function __construct( $nameSpace, &$title, Config &$config ) {
|
public function __construct( $nameSpace, $title, Config &$config ) {
|
||||||
$this->title = \Title::makeTitleSafe( $nameSpace, $title );
|
$this->title = \Title::makeTitleSafe( $nameSpace, $title );
|
||||||
$this->titleValue = $this->title->getTitleValue();
|
$this->titleValue = $this->title->getTitleValue();
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
@ -3,40 +3,19 @@
|
|||||||
* @group bovender
|
* @group bovender
|
||||||
*/
|
*/
|
||||||
class DelimitersTest extends MediaWikiTestCase {
|
class DelimitersTest extends MediaWikiTestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider provideStartOnly
|
* @dataProvider provideSplitData
|
||||||
*/
|
*/
|
||||||
public function testDelimitersWordStartOnly( $enabled, $delimiter ) {
|
public function testSplit( $input, $output ) {
|
||||||
$config = new LinkTitles\Config();
|
|
||||||
$config->wordStartOnly = $enabled;
|
|
||||||
LinkTitles\Delimiters::invalidate();
|
|
||||||
$d = LinkTitles\Delimiters::default( $config );
|
|
||||||
$this->assertSame( $delimiter, $d->wordStart );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function provideStartOnly() {
|
public static function provideSplitData() {
|
||||||
return [
|
return [
|
||||||
[ true, '(?<!\pL)' ],
|
[
|
||||||
[ false, '' ]
|
'this may be linked [[this may not be linked]]',
|
||||||
];
|
[ 'this may be linked', '[[this may not be linked]]']
|
||||||
}
|
]
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider provideEndOnly
|
|
||||||
*/
|
|
||||||
public function testDelimitersWordEndOnly( $enabled, $delimiter ) {
|
|
||||||
$config = new LinkTitles\Config();
|
|
||||||
$config->wordEndOnly = $enabled;
|
|
||||||
LinkTitles\Delimiters::invalidate();
|
|
||||||
$d = LinkTitles\Delimiters::default( $config );
|
|
||||||
$this->assertSame( $delimiter, $d->wordEnd );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function provideEndOnly() {
|
|
||||||
return [
|
|
||||||
[ true, '(?!\pL)' ],
|
|
||||||
[ false, '' ]
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
40
tests/phpunit/TargetTest.php
Normal file
40
tests/phpunit/TargetTest.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @group bovender
|
||||||
|
*/
|
||||||
|
class TargetTest extends MediaWikiTestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider provideStartOnly
|
||||||
|
*/
|
||||||
|
public function testTargetWordStartOnly( $enabled, $delimiter ) {
|
||||||
|
$config = new LinkTitles\Config();
|
||||||
|
$config->wordStartOnly = $enabled;
|
||||||
|
$target = new LinKTitles\Target( NS_MAIN, 'test page', $config );
|
||||||
|
$this->assertSame( $delimiter, $target->wordStart );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function provideStartOnly() {
|
||||||
|
return [
|
||||||
|
[ true, '(?<!\pL)' ],
|
||||||
|
[ false, '' ]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider provideEndOnly
|
||||||
|
*/
|
||||||
|
public function testTargetWordEndOnly( $enabled, $delimiter ) {
|
||||||
|
$config = new LinkTitles\Config();
|
||||||
|
$config->wordEndOnly = $enabled;
|
||||||
|
$target = new LinKTitles\Target( NS_MAIN, 'test page', $config );
|
||||||
|
$this->assertSame( $delimiter, $target->wordEnd );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function provideEndOnly() {
|
||||||
|
return [
|
||||||
|
[ true, '(?!\pL)' ],
|
||||||
|
[ false, '' ]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user