From 0d2c4c4d61a89c30b80050c736e635701fe4b870 Mon Sep 17 00:00:00 2001 From: "C. Scott Ananian" Date: Wed, 2 Oct 2013 15:28:37 -0400 Subject: [PATCH] ParserTests: allow test of precedence between interwiki links and namespaces Bug: 51680 Change-Id: I8ad82c596139824fb97d513a62513edf2941b958 --- tests/parser/parserTest.inc | 10 +++++++++- tests/parser/parserTests.txt | 16 ++++++++++++++++ tests/phpunit/includes/parser/NewParserTest.php | 13 +++++++++++-- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/tests/parser/parserTest.inc b/tests/parser/parserTest.inc index f08e9950c9..3f8d7f96af 100644 --- a/tests/parser/parserTest.inc +++ b/tests/parser/parserTest.inc @@ -143,7 +143,7 @@ class ParserTest { static function setUp() { global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache, - $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo, + $wgExtraNamespaces, $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo, $parserMemc, $wgThumbnailScriptPath, $wgScriptPath, $wgArticlePath, $wgScript, $wgStylePath, $wgExtensionAssetsPath, $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType, $wgLockManagers; @@ -182,6 +182,9 @@ class ParserTest { $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface'; $wgNamespaceAliases['Image'] = NS_FILE; $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK; + # add a namespace shadowing a interwiki link, to test + # proper precedence when resolving links. (bug 51680) + $wgExtraNamespaces[100] = 'MemoryAlpha'; // XXX: tests won't run without this (for CACHE_DB) if ( $wgMainCacheType === CACHE_DB ) { @@ -239,6 +242,11 @@ class ParserTest { 'iw_api' => '', 'iw_wikiid' => '', 'iw_local' => 0 ), + 'memoryalpha' => array( + 'iw_url' => 'http://www.memory-alpha.org/en/index.php/$1', + 'iw_api' => '', + 'iw_wikiid' => '', + 'iw_local' => 0 ), 'zh' => array( 'iw_url' => 'http://zh.wikipedia.org/wiki/$1', 'iw_api' => '', diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index 47189fc18d..e21ee3d0cf 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -4634,6 +4634,22 @@ Link to namespaces

!! end +!! article +MemoryAlpha:AlphaTest +!! text +This is an article in the MemoryAlpha namespace +(which shadows the memoryalpha interwiki link). +!! endarticle + +!! test +Namespace takes precedence over interwiki link (bug 51680) +!! input +[[MemoryAlpha:AlphaTest]] +!! result +

MemoryAlpha:AlphaTest +

+!! end + !! test Piped link to namespace !! input diff --git a/tests/phpunit/includes/parser/NewParserTest.php b/tests/phpunit/includes/parser/NewParserTest.php index 73c85f001c..ab8e77b172 100644 --- a/tests/phpunit/includes/parser/NewParserTest.php +++ b/tests/phpunit/includes/parser/NewParserTest.php @@ -37,7 +37,7 @@ class NewParserTest extends MediaWikiTestCase { } protected function setUp() { - global $wgNamespaceAliases; + global $wgNamespaceAliases, $wgContLang; global $wgHooks, $IP; parent::setUp(); @@ -132,6 +132,9 @@ class NewParserTest extends MediaWikiTestCase { $tmpHooks['ParserTestParser'][] = 'ParserTestParserHook::setup'; $tmpHooks['ParserGetVariableValueTs'][] = 'ParserTest::getFakeTimestamp'; $tmpGlobals['wgHooks'] = $tmpHooks; + # add a namespace shadowing a interwiki link, to test + # proper precedence when resolving links. (bug 51680) + $tmpGlobals['wgExtraNamespaces'] = array( 100 => 'MemoryAlpha' ); $this->setMwGlobals( $tmpGlobals ); @@ -140,10 +143,13 @@ class NewParserTest extends MediaWikiTestCase { $wgNamespaceAliases['Image'] = NS_FILE; $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK; + + MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache + $wgContLang->resetNamespaces(); # reset namespace cache } protected function tearDown() { - global $wgNamespaceAliases; + global $wgNamespaceAliases, $wgContLang; $wgNamespaceAliases['Image'] = $this->savedWeirdGlobals['image_alias']; $wgNamespaceAliases['Image_talk'] = $this->savedWeirdGlobals['image_talk_alias']; @@ -159,6 +165,9 @@ class NewParserTest extends MediaWikiTestCase { MessageCache::destroyInstance(); parent::tearDown(); + + MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache + $wgContLang->resetNamespaces(); # reset namespace cache } public static function tearDownAfterClass() { -- 2.20.1