Fix Splitter tests.

This commit is contained in:
Daniel Kraus
2017-08-30 17:48:04 +02:00
parent b27dea8709
commit 9484e5b13d
2 changed files with 30 additions and 6 deletions

View File

@ -117,7 +117,7 @@ class Splitter {
// Since there is a user option to skip headings, we make this part of the expression // Since there is a user option to skip headings, we make this part of the expression
// optional. Note that in order to use preg_split(), it is important to have only one // optional. Note that in order to use preg_split(), it is important to have only one
// capturing subpattern (which precludes the use of conditional subpatterns). // capturing subpattern (which precludes the use of conditional subpatterns).
( $this->config->parseHeadings ) ? $delimiter = '' : $delimiter = '=+.+?=+|'; ( $this->config->parseHeadings ) ? $delimiter = '' : $delimiter = '^=+.+?=+|';
$urlPattern = '[a-z]+?\:\/\/(?:\S+\.)+\S+(?:\/.*)?'; $urlPattern = '[a-z]+?\:\/\/(?:\S+\.)+\S+(?:\/.*)?';
$this->splitter = '/(' . // exclude from linking: $this->splitter = '/(' . // exclude from linking:
'\[\[.*?\]\]|' . // links '\[\[.*?\]\]|' . // links

View File

@ -22,15 +22,21 @@
/** /**
* Tests the LinKTitles\Splitter class. * Tests the LinKTitles\Splitter class.
* *
* @group bovender * @group bovender
*/ */
class SplitterTest extends MediaWikiTestCase { class SplitterTest extends MediaWikiTestCase {
/** /**
* @dataProvider provideSplitData * @dataProvider provideSplitData
*/ */
public function testSplit( $input, $expectedOutput ) { public function testSplit( $skipTemplates, $parseHeadings, $input, $expectedOutput ) {
$splitter = LinkTitles\Splitter::default(); $config = new LinkTitles\Config();
$config->skipTemplates = $skipTemplates;
$config->parseHeadings = $parseHeadings;
LinkTitles\Splitter::invalidate();
$splitter = LinkTitles\Splitter::default( $config );
$this->assertSame( $skipTemplates, $splitter->config->skipTemplates, 'Splitter has incorrect skipTemplates config');
$this->assertSame( $parseHeadings, $splitter->config->parseHeadings, 'Splitter has incorrect parseHeadings config');
$this->assertSame( $expectedOutput, $splitter->split( $input ) ); $this->assertSame( $expectedOutput, $splitter->split( $input ) );
} }
@ -38,16 +44,34 @@ class SplitterTest extends MediaWikiTestCase {
public static function provideSplitData() { public static function provideSplitData() {
return [ return [
[ [
true, // skipTemplates
false, // parseHeadings
'this may be linked [[this may not be linked]]', 'this may be linked [[this may not be linked]]',
[ 'this may be linked ', '[[this may not be linked]]', '' ] [ 'this may be linked ', '[[this may not be linked]]', '' ]
], ],
[ [
true, // skipTemplates
false, // parseHeadings
'this may be linked <gallery>this may not be linked</gallery>', 'this may be linked <gallery>this may not be linked</gallery>',
[ 'this may be linked ', '<gallery>this may not be linked</gallery>', '' ] [ 'this may be linked ', '<gallery>this may not be linked</gallery>', '' ]
], ],
[ [
'this may be linked {{mytemplate|param={{transcluded}}}}', true, // skipTemplates
[ 'this may be linked ', '{{mytemplate|param={{transcluded}}}}', '' ] false, // parseHeadings
'With skipTemplates = true, this may be linked {{mytemplate|param=link target}}',
[ 'With skipTemplates = true, this may be linked ', '{{mytemplate|param=link target}}', '' ]
],
[
false, // skipTemplates
false, // parseHeadings
'With skipTemplates = false, this may be linked {{mytemplate|param=link target}}',
[ 'With skipTemplates = false, this may be linked ', '{{mytemplate|param=', 'link target}}' ]
],
[
true, // skipTemplates
false, // parseHeadings
'With skipTemplates = true, this may be linked {{mytemplate|param={{transcluded}}}}',
[ 'With skipTemplates = true, this may be linked ', '{{mytemplate|param={{transcluded}}}}', '' ]
], ],
]; ];
} }