Page MenuHomePhabricator

Some MobileFrontend tests fail when run together with ExtensionRegistrationTest.php
Closed, ResolvedPublic

Description

To reproduce, define the following suite in your phpunit.xml.dist file:

<testsuite name="test2">
	<file>tests/phpunit/includes/registration/ExtensionRegistrationTest.php</file>
	<file>extensions/MobileFrontend/tests/phpunit/integration/MobileFrontendHooksTest.php</file>
	<file>extensions/MobileFrontend/tests/phpunit/integration/api/ApiParseExtenderTest.php</file>
</testsuite>

and run it. It'll show the following failures:

1) MobileFrontendHooksTest::testOnTitleSquidURLs
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
     0 => 'http://en.wikipedia.org/wiki/PurgeTest'
-    1 => 'http://en.m.wikipedia.org/wiki/PurgeTest'
-    2 => 'http://en.wikipedia.org/w/ind...istory'
-    3 => 'http://en.m.wikipedia.org/w/i...istory'
+    1 => 'http://en.wikipedia.org/w/index.php?title=PurgeTest&action=history'
 )

/var/www/html/w/tests/phpunit/MediaWikiTestCaseTrait.php:275
/var/www/html/w/extensions/MobileFrontend/tests/phpunit/integration/MobileFrontendHooksTest.php:243
/var/www/html/w/tests/phpunit/MediaWikiIntegrationTestCase.php:513
=== Logs generated by test case
[objectcache] [debug] MainWANObjectCache using store {class} {"class":"HashBagOStuff"}
[localisation] [debug] LocalisationCache using store LCStoreNull []
[objectcache] [debug] MainWANObjectCache using store {class} {"class":"HashBagOStuff"}
===

2) ApiParseExtenderTest::testApi with data set #0 (array('', 'I exist\n\n<span class='nomob.../span>'), array('<section', 'mf-section-0'))
Failed asserting that '<p>I exist\n
</p><p><span class="nomobile">I don't</span>\n
</p>\n
<!-- \n
NewPP limit report\n
Parsed by 2416b685e2b7\n
Cached time: 20230719005918\n
Cache expiry: 86400\n
Reduced expiry: false\n
Complications: []\n
CPU time usage: 0.002 seconds\n
Real time usage: 0.002 seconds\n
Preprocessor visited node count: 2/1000000\n
Post‐expand include size: 0/102400 bytes\n
Template argument size: 0/102400 bytes\n
Highest expansion depth: 1/100\n
Expensive parser function count: 0/100\n
Unstrip recursion depth: 0/20\n
Unstrip post‐expand size: 0/5000000 bytes\n
-->\n
<!--\n
Transclusion expansion time report (%,ms,calls,template)\n
100.00%    0.000      1 -total\n
-->\n
' contains "<section".

/var/www/html/w/extensions/MobileFrontend/tests/phpunit/integration/api/ApiParseExtenderTest.php:45
/var/www/html/w/extensions/MobileFrontend/tests/phpunit/integration/api/ApiParseExtenderTest.php:20
/var/www/html/w/tests/phpunit/MediaWikiIntegrationTestCase.php:513
=== Logs generated by test case
[objectcache] [debug] MainWANObjectCache using store {class} {"class":"HashBagOStuff"}
[localisation] [debug] LocalisationCache using store LCStoreNull []
[objectcache] [debug] MainWANObjectCache using store {class} {"class":"HashBagOStuff"}
[wfDebug] [debug] ParserFactory: using default preprocessor {"private":false}
[localisation] [debug] LocalisationCache::isExpired(en): cache missing, need to make one []
[objectcache] [debug] MainObjectStash using store {class} {"class":"HashBagOStuff"}
[ContentHandler] [info] Registered handler for MassMessageListContent: MediaWiki\MassMessage\Content\MassMessageListContentHandler []
[ContentHandler] [info] Registered handler for wikitext: WikitextContentHandler []
[ContentHandler] [info] Registered handler for javascript: JavaScriptContentHandler []
[ContentHandler] [info] Registered handler for json: JsonContentHandler []
[ContentHandler] [info] Registered handler for css: CssContentHandler []
[ContentHandler] [info] Registered handler for text: TextContentHandler []
[ContentHandler] [info] Registered handler for unknown: FallbackContentHandler []
[wfDebug] [debug] ApiMain::setCacheMode: setting cache mode anon-public-user-private {"private":false}
[MessageCache] [debug] MessageCache using store {class} {"class":"HashBagOStuff"}
[GlobalTitleFail] [info] RequestContext::getTitle called with no title set. {"exception":{}}
===

3) ApiParseExtenderTest::testApi with data set #1 (array('1', 'Lede<h2>Section1</h2>Text<h2>...2>Text'), array('<section', 'mf-section-0', 'section-heading', 'mfTempOpenSection', '<h2'))
Failed asserting that '<p>Lede</p><h2><span class="mw-headline" id="Section1">Section1</span></h2><p>Text</p><h2><span class="mw-headline" id="Section2">Section2</span></h2><p>Text</p>\n
<!-- \n
NewPP limit report\n
Parsed by 2416b685e2b7\n
Cached time: 20230719005918\n
Cache expiry: 86400\n
Reduced expiry: false\n
Complications: []\n
CPU time usage: 0.004 seconds\n
Real time usage: 0.004 seconds\n
Preprocessor visited node count: 1/1000000\n
Post‐expand include size: 0/102400 bytes\n
Template argument size: 0/102400 bytes\n
Highest expansion depth: 1/100\n
Expensive parser function count: 0/100\n
Unstrip recursion depth: 0/20\n
Unstrip post‐expand size: 0/5000000 bytes\n
-->\n
<!--\n
Transclusion expansion time report (%,ms,calls,template)\n
100.00%    0.000      1 -total\n
-->\n
' contains "<section".

/var/www/html/w/extensions/MobileFrontend/tests/phpunit/integration/api/ApiParseExtenderTest.php:45
/var/www/html/w/extensions/MobileFrontend/tests/phpunit/integration/api/ApiParseExtenderTest.php:20
/var/www/html/w/tests/phpunit/MediaWikiIntegrationTestCase.php:513
=== Logs generated by test case
[objectcache] [debug] MainWANObjectCache using store {class} {"class":"HashBagOStuff"}
[localisation] [debug] LocalisationCache using store LCStoreNull []
[objectcache] [debug] MainWANObjectCache using store {class} {"class":"HashBagOStuff"}
[wfDebug] [debug] ParserFactory: using default preprocessor {"private":false}
[localisation] [debug] LocalisationCache::isExpired(en): cache missing, need to make one []
[objectcache] [debug] MainObjectStash using store {class} {"class":"HashBagOStuff"}
[ContentHandler] [info] Registered handler for MassMessageListContent: MediaWiki\MassMessage\Content\MassMessageListContentHandler []
[ContentHandler] [info] Registered handler for wikitext: WikitextContentHandler []
[ContentHandler] [info] Registered handler for javascript: JavaScriptContentHandler []
[ContentHandler] [info] Registered handler for json: JsonContentHandler []
[ContentHandler] [info] Registered handler for css: CssContentHandler []
[ContentHandler] [info] Registered handler for text: TextContentHandler []
[ContentHandler] [info] Registered handler for unknown: FallbackContentHandler []
[wfDebug] [debug] ApiMain::setCacheMode: setting cache mode anon-public-user-private {"private":false}
[MessageCache] [debug] MessageCache using store {class} {"class":"HashBagOStuff"}
[GlobalTitleFail] [info] RequestContext::getTitle called with no title set. {"exception":{}}
===

Event Timeline

This is caused by ExtensionRegistrationTest::setUp():

protected function setUp(): void {
	global $wgHooks;

	// For the purpose of this test, make $wgHooks behave like a real global config array.
	// The FauxGlobalHooksArray will be restored by the testing framework automatically.
	$wgHooks = [];
}

What the comment says doesn't seem completely true. When the MF test runs, there are no registered hooks.

Change 939676 had a related patch set uploaded (by Daimona Eaytoy; author: Daimona Eaytoy):

[mediawiki/core@master] Make sure to reset wgHooks in ExtensionRegistrationTest

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

Change 939676 merged by jenkins-bot:

[mediawiki/core@master] Make sure to reset wgHooks in ExtensionRegistrationTest

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