mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 01:39:30 +02:00
Linker tests for templates.
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* Unit tests for the Linker class, i.e. the core functionality
|
||||
*
|
||||
* Copyright 2012-2017 Daniel Kraus <bovender@bovender.de> ('bovender')
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -26,8 +28,8 @@
|
||||
* The test class is prefixed with 'LinkTitles' to avoid a naming collision
|
||||
* with a class that exists in the MediaWiki core.
|
||||
*
|
||||
* Ideally the test classes should be namespaced, but when you do that, they
|
||||
* will no longer be automatically discovered.
|
||||
* (Ideally the test classes should be namespaced, but when you do that, they
|
||||
* will no longer be automatically discovered.)
|
||||
*
|
||||
* @group Database
|
||||
*/
|
||||
@ -39,6 +41,45 @@ class LinkTitlesLinkerTest extends LinkTitles\TestCase {
|
||||
parent::setUp(); // call last to have the Targets object invalidated after inserting the page
|
||||
}
|
||||
|
||||
|
||||
public function addDBDataOnce() {
|
||||
$this->insertPage( 'link target', 'This page serves as a link target' );
|
||||
parent::addDBDataOnce(); // call parent after adding page to have targets invalidated
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider provideLinkContentData
|
||||
*/
|
||||
public function testLinkContentTemplates( $skipTemplates, $input, $expectedOutput ) {
|
||||
$config = new LinkTitles\Config();
|
||||
$config->firstOnly = false;
|
||||
$config->skipTemplates = $skipTemplates;
|
||||
$linker = new LinkTitles\Linker( $config );
|
||||
$this->assertSame( $expectedOutput, $linker->linkContent( $this->title, $input ));
|
||||
}
|
||||
|
||||
public function provideLinkContentTemplatesData() {
|
||||
return [
|
||||
[
|
||||
true, // skipTemplates
|
||||
'With skipTemplates = true, a {{template|with=link target}} in it should not be linked',
|
||||
'With skipTemplates = true, a {{template|with=link target}} in it should not be linked',
|
||||
],
|
||||
[
|
||||
false, // skipTemplates
|
||||
'With skipTemplates = false, a {{template|with=link target}} in it should be linked',
|
||||
'With skipTemplates = false, a {{template|with=[[link target]]}} in it should be linked',
|
||||
],
|
||||
[
|
||||
false, // skipTemplates
|
||||
'With skipTemplates = false, a {{template|with=already linked [[link target]]}} in it should not be linked again',
|
||||
'With skipTemplates = false, a {{template|with=already linked [[link target]]}} in it should not be linked again',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider provideLinkContentSmartModeData
|
||||
*/
|
||||
@ -153,9 +194,40 @@ class LinkTitlesLinkerTest extends LinkTitles\TestCase {
|
||||
|
||||
public function testLinkContentBlackList() {
|
||||
$config = new LinkTitles\Config();
|
||||
$config->blackList = [ 'Foo', 'Link target', 'Bar' ];
|
||||
$config->blackList = [ 'Foo', 'link target', 'Bar' ];
|
||||
$linker = new LinkTitles\Linker( $config );
|
||||
$text = 'If the link target is blacklisted, it should not be linked';
|
||||
$this->assertSame( $text, $linker->linkContent( $this->title, $text ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideLinkContentNameSpacesData
|
||||
*/
|
||||
public function testLinkContentNameSpaces( $nameSpaces, $input, $expectedOutput ) {
|
||||
$ns = 3000;
|
||||
$this->setMwGlobals( [
|
||||
"wgExtraNameSpaces[$ns]" => 'custom_namespace'
|
||||
] );
|
||||
$this->insertPage( 'in custom namespace', 'This is a page in a custom namespace', $ns );
|
||||
$config = new LinkTitles\Config();
|
||||
$config->nameSpaces = $nameSpaces;
|
||||
$linker = new LinkTitles\Linker( $config );
|
||||
$this->assertSame( $expectedOutput, $linker->linkContent( $this->title, $input ));
|
||||
}
|
||||
|
||||
public function provideLinkContentNameSpacesData() {
|
||||
return [
|
||||
[
|
||||
[], // nameSpaces
|
||||
'With nameSpaces = [], page in custom namespace should not be linked',
|
||||
'With firstOnly = [], page in custom namespace should not be linked'
|
||||
],
|
||||
[
|
||||
[ 3000 ], // nameSpaces
|
||||
'With nameSpaces = [], page in custom namespace should be linked',
|
||||
'With firstOnly = [], page [[in custom namespace]] should be linked'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user