Add Target unit test.

This commit is contained in:
Daniel Kraus
2017-08-27 22:25:22 +02:00
parent 35b174771e
commit 3f2141e6c7
3 changed files with 59 additions and 46 deletions

View File

@ -28,10 +28,17 @@ namespace LinkTitles;
*/
class Target {
/**
* \TitleValue object for the current target page title.
* @var \TitleValue $titleValue;
* A Title object for the target page currently being examined.
* @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
@ -47,19 +54,6 @@ class Target {
*/
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.
* @var Config $config
@ -74,7 +68,7 @@ class Target {
* @param Int $nameSpace Name space 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->titleValue = $this->title->getTitleValue();
$this->config = $config;

View File

@ -3,40 +3,19 @@
* @group bovender
*/
class DelimitersTest extends MediaWikiTestCase {
/**
* @dataProvider provideStartOnly
* @dataProvider provideSplitData
*/
public function testDelimitersWordStartOnly( $enabled, $delimiter ) {
$config = new LinkTitles\Config();
$config->wordStartOnly = $enabled;
LinkTitles\Delimiters::invalidate();
$d = LinkTitles\Delimiters::default( $config );
$this->assertSame( $delimiter, $d->wordStart );
public function testSplit( $input, $output ) {
}
public static function provideStartOnly() {
public static function provideSplitData() {
return [
[ true, '(?<!\pL)' ],
[ false, '' ]
];
}
/**
* @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, '' ]
[
'this may be linked [[this may not be linked]]',
[ 'this may be linked', '[[this may not be linked]]']
]
];
}
}

View 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, '' ]
];
}
}