mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 09:49:31 +02:00
Test namespace handling.
This commit is contained in:
@ -41,7 +41,6 @@ class LinkTitlesLinkerTest extends LinkTitles\TestCase {
|
|||||||
parent::setUp(); // call last to have the Targets object invalidated after inserting the page
|
parent::setUp(); // call last to have the Targets object invalidated after inserting the page
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function addDBData() {
|
public function addDBData() {
|
||||||
$this->title = $this->insertPage( 'source page', 'This page is the test page' )['title'];
|
$this->title = $this->insertPage( 'source page', 'This page is the test page' )['title'];
|
||||||
$this->insertPage( 'link target', 'This page serves as a link target' );
|
$this->insertPage( 'link target', 'This page serves as a link target' );
|
||||||
@ -83,7 +82,6 @@ class LinkTitlesLinkerTest extends LinkTitles\TestCase {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider provideLinkContentSmartModeData
|
* @dataProvider provideLinkContentSmartModeData
|
||||||
*/
|
*/
|
||||||
@ -217,40 +215,45 @@ class LinkTitlesLinkerTest extends LinkTitles\TestCase {
|
|||||||
// Tests for namespace handling are commented out until I find a way to add
|
// Tests for namespace handling are commented out until I find a way to add
|
||||||
// a custom namespace during testing. (The assertTrue assertion below fails.)
|
// a custom namespace during testing. (The assertTrue assertion below fails.)
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * @dataProvider provideLinkContentNamespacesData
|
* @dataProvider provideLinkContentNamespacesData
|
||||||
// */
|
*/
|
||||||
// public function testLinkContentNamespaces( $namespaces, $input, $expectedOutput ) {
|
public function testLinkContentTargetNamespaces( $namespaces, $input, $expectedOutput ) {
|
||||||
// $ns = 4000;
|
$config = new LinkTitles\Config();
|
||||||
// $this->setMwGlobals( [
|
$config->targetNamespaces = $namespaces;
|
||||||
// "wgExtraNamespaces[$ns]" => 'custom_namespace'
|
|
||||||
// ] );
|
|
||||||
// // global $wgExtraNamespaces;
|
|
||||||
// // global $wgContentNamespaces;
|
|
||||||
// // $wgContentNamespaces[] = $ns;
|
|
||||||
// // $wgExtraNamespaces[$ns] = 'custom_adsf';
|
|
||||||
// $this->insertPage( 'in custom namespace', 'This is a page in a custom namespace', $ns );
|
|
||||||
// $this->assertTrue( MWNamespace::exists( $ns ), "The name space with id $ns should exist!" );
|
|
||||||
// LinKTitles\Targets::invalidate();
|
|
||||||
// $config = new LinkTitles\Config();
|
|
||||||
// $config->namespaces = $namespaces;
|
|
||||||
// $linker = new LinkTitles\Linker( $config );
|
|
||||||
// $this->assertSame( $expectedOutput, $linker->linkContent( $this->title, $input ));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public function provideLinkContentNamespacesData() {
|
$ns = 4000;
|
||||||
// return [
|
$nsText = 'customnamespace';
|
||||||
// [
|
$this->mergeMwGlobalArrayValue( 'wgExtraNamespaces', [ $ns => $nsText ] );
|
||||||
// [], // namespaces
|
|
||||||
// 'With namespaces = [], page in custom namespace should not be linked',
|
|
||||||
// 'With namespaces = [], page in custom namespace should not be linked'
|
|
||||||
// ],
|
|
||||||
// [
|
|
||||||
// [ 4000 ], // namespaces
|
|
||||||
// 'With namespaces = [ 4000 ], page in custom namespace should be linked',
|
|
||||||
// 'With namespaces = [ 4000 ], page [[custom_namespace:in custom namespace]] should be linked'
|
|
||||||
// ],
|
|
||||||
// ];
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
// Reset namespace caches.
|
||||||
|
// See https://stackoverflow.com/q/45974979/270712
|
||||||
|
MWNamespace::getCanonicalNamespaces( true );
|
||||||
|
global $wgContLang;
|
||||||
|
$wgContLang->resetNamespaces();
|
||||||
|
$this->assertTrue( MWNamespace::exists( $ns ), "The namespace with id $ns should exist!" );
|
||||||
|
|
||||||
|
$this->insertPage( "in custom namespace", 'This is a page in a custom namespace', $ns );
|
||||||
|
LinKTitles\Targets::invalidate();
|
||||||
|
$linker = new LinkTitles\Linker( $config );
|
||||||
|
$source = LinkTitles\Source::createFromTitleAndText( $this->title, $input, $config );
|
||||||
|
$result = $linker->linkContent( $source );
|
||||||
|
if ( !$result ) { $result = $input; }
|
||||||
|
$this->assertSame( $expectedOutput, $result );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideLinkContentNamespacesData() {
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
[], // namespaces
|
||||||
|
'With targetNamespaces = [], page in custom namespace should not be linked',
|
||||||
|
'With targetNamespaces = [], page in custom namespace should not be linked'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[ 4000 ], // namespaces
|
||||||
|
'With targetNamespaces = [ 4000 ], page in custom namespace should be linked',
|
||||||
|
'With targetNamespaces = [ 4000 ], page [[customnamespace:In custom namespace|in custom namespace]] should be linked'
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,13 +28,15 @@
|
|||||||
*/
|
*/
|
||||||
class TargetsTest extends LinkTitles\TestCase {
|
class TargetsTest extends LinkTitles\TestCase {
|
||||||
|
|
||||||
/**
|
|
||||||
* This test asserts that the list of potential link targets is 0
|
|
||||||
* @return [type] [description]
|
|
||||||
*/
|
|
||||||
public function testTargets() {
|
public function testTargets() {
|
||||||
|
$config = new LinkTitles\Config();
|
||||||
|
// Include the custom namespace with index 4000 in the count. This is a
|
||||||
|
// very ugly hack. If the custom namespace index in
|
||||||
|
// LinkTitlesLinkerTest::testLinkContentTargetNamespaces() is every changed,
|
||||||
|
// this test will fail.
|
||||||
|
$config->targetNamespaces = [ 4000 ];
|
||||||
$title = \Title::newFromText( 'link target' );
|
$title = \Title::newFromText( 'link target' );
|
||||||
$targets = LinkTitles\Targets::singleton( $title, new LinkTitles\Config() );
|
$targets = LinkTitles\Targets::singleton( $title, $config );
|
||||||
|
|
||||||
// Count number of articles: Inspired by updateArticleCount.php maintenance
|
// Count number of articles: Inspired by updateArticleCount.php maintenance
|
||||||
// script: https://doc.wikimedia.org/mediawiki-core/master/php/updateArticleCount_8php_source.html
|
// script: https://doc.wikimedia.org/mediawiki-core/master/php/updateArticleCount_8php_source.html
|
||||||
|
Reference in New Issue
Block a user