mirror of
				https://github.com/diocloid/LinkTitles.git
				synced 2025-10-22 05:42:32 +02:00 
			
		
		
		
	Fix Splitter tests.
This commit is contained in:
		@@ -117,7 +117,7 @@ class Splitter {
 | 
			
		||||
		// 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
 | 
			
		||||
		// capturing subpattern (which precludes the use of conditional subpatterns).
 | 
			
		||||
		( $this->config->parseHeadings ) ? $delimiter = '' : $delimiter = '=+.+?=+|';
 | 
			
		||||
		( $this->config->parseHeadings ) ? $delimiter = '' : $delimiter = '^=+.+?=+|';
 | 
			
		||||
		$urlPattern = '[a-z]+?\:\/\/(?:\S+\.)+\S+(?:\/.*)?';
 | 
			
		||||
		$this->splitter = '/(' .                     // exclude from linking:
 | 
			
		||||
			'\[\[.*?\]\]|' .                            // links
 | 
			
		||||
 
 | 
			
		||||
@@ -22,15 +22,21 @@
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Tests the LinKTitles\Splitter class.
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 * @group bovender
 | 
			
		||||
 */
 | 
			
		||||
class SplitterTest extends MediaWikiTestCase {
 | 
			
		||||
	/**
 | 
			
		||||
	 * @dataProvider provideSplitData
 | 
			
		||||
	 */
 | 
			
		||||
	public function testSplit( $input, $expectedOutput ) {
 | 
			
		||||
		$splitter = LinkTitles\Splitter::default();
 | 
			
		||||
	public function testSplit( $skipTemplates, $parseHeadings, $input, $expectedOutput ) {
 | 
			
		||||
		$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 ) );
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -38,16 +44,34 @@ class SplitterTest extends MediaWikiTestCase {
 | 
			
		||||
	public static function provideSplitData() {
 | 
			
		||||
		return [
 | 
			
		||||
			[
 | 
			
		||||
				true, // skipTemplates
 | 
			
		||||
				false, // parseHeadings
 | 
			
		||||
				'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 {{mytemplate|param={{transcluded}}}}',
 | 
			
		||||
				[ 'this may be linked ', '{{mytemplate|param={{transcluded}}}}', '' ]
 | 
			
		||||
				true, // skipTemplates
 | 
			
		||||
				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}}}}', '' ]
 | 
			
		||||
			],
 | 
			
		||||
		];
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user