Page MenuHomePhabricator

SkinMinervaTest.php fails when run in a suite with SpecialAvailableBadgesTest.php
Closed, ResolvedPublic

Description

Problem

The SkinMinervaTest class fails if run in a test suite with SpecialAvailableBadgesTest before it. 1 test errors and 3 tests fail. Running the classes individually causes no problems.

Steps to reproduce
In a Mediawiki checkout with the Wikibase extension and Minerva skin installed.

  1. Copy phpunit.dist.xml to phpunit.xml
  2. Add a test suite with the following two tests:
 <testsuite name="failing_group">
    <file>extensions/Wikibase/repo/tests/phpunit/includes/Specials/SpecialAvailableBadgesTest.php</file>
    <file>skins/MinervaNeue/tests/phpunit/skins/SkinMinervaTest.php</file>
</testsuite>
  1. Run the named test suite:
mw docker mediawiki exec -- composer run phpunit:entrypoint -- --testsuite failing_group

Observed behaviour
The test run fails:

$ mw docker mediawiki exec -- composer run phpunit:entrypoint -- --testsuite failing_group
> phpunit '--testsuite' 'failing_group'
Running with MediaWiki settings because there might be integration tests
PHPUnit 9.6.16 by Sebastian Bergmann and contributors.

....F..FF....E..................                                  32 / 32 (100%)

Time: 00:01.601, Memory: 62.50 MB

There was 1 error:

1) MediaWiki\Minerva\SkinMinervaTest::testGetTabsDataNoPageTabs
RuntimeException: Database backend disabled

/var/www/html/w/includes/libs/rdbms/loadbalancer/LoadBalancerDisabled.php:72
...

--

There were 3 failures:

1) MediaWiki\Minerva\SkinMinervaTest::testHasPageActions with data set #2 (0, 'Main Page', 'view', false)
Failed asserting that true matches expected false.

/var/www/html/w/skins/MinervaNeue/tests/phpunit/skins/SkinMinervaTest.php:90

2) MediaWiki\Minerva\SkinMinervaTest::testHasPageTabs with data set #1 (array(false), 0, 'Main Page', 'view', false)
Failed asserting that true matches expected false.

/var/www/html/w/skins/MinervaNeue/tests/phpunit/skins/SkinMinervaTest.php:122

3) MediaWiki\Minerva\SkinMinervaTest::testHasPageTabs with data set #2 (array(false), 1, 'Main Page', 'view', false)
Failed asserting that true matches expected false.

/var/www/html/w/skins/MinervaNeue/tests/phpunit/skins/SkinMinervaTest.php:122
===

ERRORS!
Tests: 32, Assertions: 51, Errors: 1, Failures: 3.

Expected Behaviour
The tests should pass.

Event Timeline

Had a look into this. This seems to be (as usual) a combination of incomplete setUp/tearDown and global state.

In SpecialAvailableBadgesTest, we set the language to qqx:

	protected function setUp(): void {
		parent::setUp();

		$this->setContentLang( 'qqx' );
		$this->setUserLang( 'qqx' );
	}

setContentLang here is deprecated, there is no corresponding tearDown, and the code seems unnecessary (the test passes if the setup is removed).

In SkinMinerva, hasPageActions relies on a check of $title->isMainPage():

	private function hasPageActions() {
		$title = $this->getTitle();
		return !$title->isSpecialPage() && !$title->isMainPage() &&
			$this->getContext()->getActionName() === 'view';
	}

and Title::isMainPage was changed (in Sep 2023 - T302186) to include a cached copy of a main page object:

	public function isMainPage() {
		/** @var Title|null */
		static $cachedMainPage;
		if ( $cachedMainPage === null ) {
			$cachedMainPage = self::newMainPage();
		}
		return $this->equals( $cachedMainPage );
	}

This equals check seems to be sensitive to the language in use. With language set to qqx, the main page gets the key (mainpage), whereas by default it has the key Main_Page. This difference causes the comparison to fail when the two tests are run together in the same suite, sending the code down the getActionName path.

For now, I propose simply to remove the setUp in SpecialAvailableBadgesTest and see what happens.

Change #1049495 had a related patch set uploaded (by Arthur taylor; author: Arthur taylor):

[mediawiki/extensions/Wikibase@master] Remove deprecated `setContentLang` call

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

Change #1049495 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Remove deprecated `setContentLang` call

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

Change #1052273 had a related patch set uploaded (by Arthur taylor; author: Arthur taylor):

[mediawiki/extensions/Wikibase@master] Add strict types to modified test file

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

Change #1052273 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Add strict types to modified test file

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