Page MenuHomePhabricator

Parsertest fails: Namespace takes precedence over interwiki link (T53680)
Closed, ResolvedPublic

Description

With MediaWiki and a MySQL database, when I run the PHPUnit group Database one of the parser test fails mysteriously:

1) ParserIntegrationTest::testParse with data set "parserTests.txt: Namespace takes precedence over interwiki link (T53680)" ('[details omitted]')
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'<p><a href="/wiki/MemoryAlpha:AlphaTest" title="MemoryAlpha:AlphaTest">MemoryAlpha:AlphaTest</a>
+'<p><a href="/wiki/Special:Badtitle/NS100:AlphaTest" title=":AlphaTest">MemoryAlpha:AlphaTest</a>
 </p>'

I haven't looked into it, it seems a namespace MemoryAlpha / id 100 is not properly initialized. The debug log has:

Title::getNsText: Unknown namespace ID: 100
Title::getNsText: Unknown namespace ID: 100
Title::getNsText: Unknown namespace ID: 100

Reproduction

php phpunit.php  --debug-tests --filter '(ParserMethodsTest::testValidCovers|T53680)'

Event Timeline

hashar created this task.Mar 23 2018, 6:14 PM
Restricted Application added subscribers: TerraCodes, Aklapper. · View Herald TranscriptMar 23 2018, 6:14 PM

ParserMethodsTest are run before and the class extends MediaWikiLangTestCase. Its setup function:

tests/phpunit/MediaWikiLangTestCase.php
abstract class MediaWikiLangTestCase extends MediaWikiTestCase {
    protected function setUp() {
        global $wgLanguageCode, $wgContLang;

        if ( $wgLanguageCode != $wgContLang->getCode() ) {
            throw new MWException( "Error in MediaWikiLangTestCase::setUp(): " .
                "\$wgLanguageCode ('$wgLanguageCode') is different from " .
                "\$wgContLang->getCode() (" . $wgContLang->getCode() . ")" );
        }

        parent::setUp();

        $this->setUserLang( 'en' );
        // For mainpage to be 'Main Page'
        $this->setContentLang( 'en' );

        MessageCache::singleton()->disable();
    }
}

If comment out the $this->setContentLang( 'en' ); there, the parser test passes!

A common pattern seems to add:

global $wgContLang;
MWNamespace::clearCaches();
$wgContLang->resetNamespaces();

That does not fix it though.

hashar updated the task description. (Show Details)Mar 24 2018, 9:49 PM
hashar updated the task description. (Show Details)Mar 24 2018, 10:02 PM

Change 421789 had a related patch set uploaded (by Hashar; owner: Hashar):
[mediawiki/core@master] ParserTest: clear Language namespaces cache

https://gerrit.wikimedia.org/r/421789

Change 421866 had a related patch set uploaded (by Hashar; owner: Hashar):
[integration/quibble@master] Split PHPUnit Database tests

https://gerrit.wikimedia.org/r/421866

Change 421789 merged by jenkins-bot:
[mediawiki/core@master] ParserTest: clear Language namespaces cache

https://gerrit.wikimedia.org/r/421789

hashar closed this task as Resolved.Mar 26 2018, 6:49 PM
hashar claimed this task.
hashar added subscribers: Nikerabbit, Legoktm.

Thanks @Nikerabbit & @Legoktm . I might eventually need to backport. But not until I start looking at the non master branches :]

Change 421866 merged by jenkins-bot:
[integration/quibble@master] Split PHPUnit Database tests

https://gerrit.wikimedia.org/r/421866