From 3f2141e6c743350f337db164c95bc38392b51561 Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Sun, 27 Aug 2017 22:25:22 +0200 Subject: [PATCH] Add Target unit test. --- includes/Target.php | 28 +++++++++------------- tests/phpunit/DelimitersTest.php | 37 +++++++---------------------- tests/phpunit/TargetTest.php | 40 ++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 46 deletions(-) create mode 100644 tests/phpunit/TargetTest.php diff --git a/includes/Target.php b/includes/Target.php index f2457d8..5eec4c1 100644 --- a/includes/Target.php +++ b/includes/Target.php @@ -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; diff --git a/tests/phpunit/DelimitersTest.php b/tests/phpunit/DelimitersTest.php index 7073c00..23d4910 100644 --- a/tests/phpunit/DelimitersTest.php +++ b/tests/phpunit/DelimitersTest.php @@ -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, '(?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]]'] + ] ]; } } diff --git a/tests/phpunit/TargetTest.php b/tests/phpunit/TargetTest.php new file mode 100644 index 0000000..5cc9691 --- /dev/null +++ b/tests/phpunit/TargetTest.php @@ -0,0 +1,40 @@ +wordStartOnly = $enabled; + $target = new LinKTitles\Target( NS_MAIN, 'test page', $config ); + $this->assertSame( $delimiter, $target->wordStart ); + } + + public static function provideStartOnly() { + return [ + [ true, '(?wordEndOnly = $enabled; + $target = new LinKTitles\Target( NS_MAIN, 'test page', $config ); + $this->assertSame( $delimiter, $target->wordEnd ); + } + + public static function provideEndOnly() { + return [ + [ true, '(?!\pL)' ], + [ false, '' ] + ]; + } +}