diff options
author | Timo Tijhof <krinkle@fastmail.com> | 2023-10-19 17:26:43 -0700 |
---|---|---|
committer | Krinkle <krinkle@fastmail.com> | 2024-05-05 00:00:01 +0000 |
commit | c02513c97e14f7513536e39d12889f7f576a4955 (patch) | |
tree | ba905bcabed1ba88bdcfc3f4764e2a362d54d5ce /tests/common | |
parent | 397d39fc4adbc0c4e92cfdf2ae7e23f3366da934 (diff) | |
download | mediawikicore-c02513c97e14f7513536e39d12889f7f576a4955.tar.gz mediawikicore-c02513c97e14f7513536e39d12889f7f576a4955.zip |
phpunit: Fix tests relying on implicit wgScript/wgArticlePath
A number of tests have hardcoded expections that pass only in WMF CI
where Quibble has LocalSettings.php with $wgScript and $wgArticlePath
set a certain way.
We could fix these by adding setMwGlobals() in their tests, as we
often do, but these are so often forgotten that I'd rather we just
add them to TestSetup.php so that it is simply impossible to write a
test that that passes locally for you (if you have the same config)
but not for someone else.
There is a larger project in there somewhere about expanding this
slowly such that we basically only pluck DB-settings and extension
enablement from LocalSettings and otherwise run the tests with the
default settings in PHPUnit. Pretty much by definition, any (other)
setting you have in LocalSettings is irrelevant because it either:
1. has no effect on the test (majority, harmless either way),
2. has a custom default via TestSetup.php (which has precedence over
LocalSettings.php),
3. is relevant to the code being tested and the test case correctly
calls setMwGlobals() to ensure a consistent value during test.
4. is relevant to the tested code but has no override, thus only
passes if you happen to have the "right" value set for it
(undesirable).
Case 4 is already categorically impossible for the most common config
settings that influence random code because we give them a value
in TestSetup.php. This patch expands that to include $wgScript
and $wgArticlePath. Perhaps in the future we can think about a way
to do this automatically by either re-applying MainConfigSchema
(sans db settings) or by only selectively applying LocalSettings.php
in the first place.
This patch follows-up I072ddf89562fe, which added a test case in
WikitextContentHandlerIntegrationTest.php that assumed "/index.php"
as the value of $wgScript. This passes in WMF CI since Quibble uses
that value, but the tests failed in most local development installs
since those tend to use "/w" instead.
Rather than one-off fixing that one test with overrideConfigValues(),
switch to a more general fixture, since the precise values don't
matter for this test.
Bug: T349087
Bug: T277470
Change-Id: If4304b7ca4a838bd892d4516a0b5c6dfbc30986e
Diffstat (limited to 'tests/common')
-rw-r--r-- | tests/common/TestSetup.php | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/common/TestSetup.php b/tests/common/TestSetup.php index 804edc23dec9..225963558952 100644 --- a/tests/common/TestSetup.php +++ b/tests/common/TestSetup.php @@ -34,6 +34,8 @@ class TestSetup { * of a Maintenance subclass which then gets called via MW_SETUP_CALLBACK in Setup.php. */ public static function applyInitialConfig() { + global $wgScriptPath, $wgScript, $wgResourceBasePath, $wgStylePath, $wgExtensionAssetsPath; + global $wgArticlePath, $wgActionPaths, $wgVariantArticlePath, $wgUploadNavigationUrl; global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType, $wgSessionCacheType; global $wgMainStash, $wgChronologyProtectorStash; global $wgLanguageConverterCacheType, $wgUseDatabaseMessages; @@ -54,6 +56,17 @@ class TestSetup { $wgDevelopmentWarnings = true; $wgDBStrictWarnings = true; + // Server URLs + $wgScriptPath = ''; + $wgScript = '/index.php'; + $wgResourceBasePath = ''; + $wgStylePath = '/skins'; + $wgExtensionAssetsPath = '/extensions'; + $wgArticlePath = '/wiki/$1'; + $wgActionPaths = []; + $wgVariantArticlePath = false; + $wgUploadNavigationUrl = false; + // Make sure all caches and stashes are either disabled or use // in-process cache only to prevent tests from using any preconfigured // cache meant for the local wiki from outside the test run. |