ParserTests: allow test of precedence between interwiki links and namespaces
authorC. Scott Ananian <cscott@cscott.net>
Wed, 2 Oct 2013 19:28:37 +0000 (15:28 -0400)
committerC. Scott Ananian <cscott@cscott.net>
Wed, 2 Oct 2013 20:11:33 +0000 (16:11 -0400)
Bug: 51680
Change-Id: I8ad82c596139824fb97d513a62513edf2941b958

tests/parser/parserTest.inc
tests/parser/parserTests.txt
tests/phpunit/includes/parser/NewParserTest.php

index f08e995..3f8d7f9 100644 (file)
@@ -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' => '',
index 47189fc..e21ee3d 100644 (file)
@@ -4634,6 +4634,22 @@ Link to namespaces
 </p>
 !! 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
+<p><a href="/wiki/MemoryAlpha:AlphaTest" title="MemoryAlpha:AlphaTest">MemoryAlpha:AlphaTest</a>
+</p>
+!! end
+
 !! test
 Piped link to namespace
 !! input
index 73c85f0..ab8e77b 100644 (file)
@@ -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() {