Commit graph

257 commits

Author SHA1 Message Date
Timo Tijhof
f67f0298d1 ResourceLoader: Add structure test to detect incompatible requiresES6
Bug: T316324
Depends-On: I12f8ebb5c6b61fb7dadeca282dab123c85b0a6a3
Depends-On: I15cec4dc86513373e74d401d0ffdc580385dd890
Depends-On: If57518a1ba6ee96dbf9ef2b9b9aff9242a8dc61c
Depends-On: Ie0f36ddda3bca0a5812887374fb6c82982b98013
Depends-On: I2f1ed2b7451b3789498ac15a285b5ec3b0e53f7b
Depends-On: Iaf04c3a5d64d268b582823eb0e1cc855445d776c
Depends-On: Iffaf7186db4bcdf4e169f2f61b556016860e769e
Depends-On: I601c53e7116f8ddeb1411e4a1e1bd452d414330a
Depends-On: I8f10750b2bc53e656eb636883213b04d4c277c4f
Change-Id: Ibb1d480a538a612f14645df2928f7604abde9fce
2022-08-31 18:13:52 +00:00
Umherirrender
6dcb1ebe76 tests: Change multiple calls from overrideConfigValue to overrideConfigValues
Also change loops to multi-value function

Change-Id: I2301cc246b7f8ca3028d44d70756a5e1ba04e82d
2022-08-17 12:08:50 +00:00
daniel
7f4ed4ea11 SettingsTest: check that the current config didn't trigger warnings.
SettingsBuilder collects warnings about issues with the configuration.
The warnings are so far only surfaced by the installer.
This change adds a structure test that ensures that there are no
warnings.

Change-Id: I92f80ceb8e9eda20ad1de35fa22ed1db7ffcb692
2022-07-22 18:01:13 +02:00
daniel
e8cc4c8f91 Fix type declarations in MainConfigSchema
Validating against the live schema on the WMF cluster exposed several
issues with the config schema. Mostly settings declared to be lists
which are actually associative arrays.

This also removes deprecation markers for some settings that are still
in active use, just discouraged or unstable.

Change-Id: I63e816edd1a561bda6063f8558ccce88c113df3f
2022-07-15 16:11:50 +02:00
Derick Alangi
f00cd03580 tests: Make use of overrideConfig(Value|Values) where needed
As we slowly move away from using globals, overrideConfigValue()
and overrideConfigValues() were introduced as a way to override
test configs between tests.

Under the hood, it just calls setMwGlobals() which resets services,
so take note.

Part 1: Directories covered are: languages/, maintenance/, tests/,
structure/ and includes/Permissions/.

Depends-On: I618b16c6d99c94eb2e7edcf05e888a65f7156754
Change-Id: If56f7d10d79f3a9824a52091a2b544d8653dd7b6
2022-07-11 21:15:26 +01:00
daniel
5e928f39e8 Dynamic defaults: fix $wgLocaltimezone being empty
Apparently, $wgLocaltimezone is set to the empty string in many
existing LocalSettings.php file, presumably because the installer
failed to detect the correct time zone.

The new code for handling automatic defaults will only trigger if
$wgLocaltimezone is null, not when it is otherwise empty.

This adds fallback code in strategic places to ensure that the empty
string is handled correctly.

Bug: T305093
Change-Id: I39226466f2bb6a36823ae9032fc62f981eabc64a
2022-07-09 18:59:32 +02:00
Lucas Werkmeister
c3c5b6c1b4 Remove 'ignoreKeys' from config schema
Unused since change I88754b52c2 (commit 9e95539fc9) – this was only used
for SessionProviders, which is now a map/object instead.

Change-Id: I8da686e6379eb33a63799874fb44f9b0030ab5ba
2022-07-06 10:46:58 +02:00
Tim Starling
8d90307c50 Fix typos
Change-Id: I2c01adb70e179abbeb6c5ae8bee3abcbdbac8edf
2022-06-30 09:44:00 +10:00
daniel
f2df03704e Add support for nested property schemas in MainConfigSchema.
This adds support for JSONSchema style property declarations with nested
schemas. This is a step towards using more nested structured for
configuration, rather than adding to the over 700 keys already defined
in the main config schema.

Defaults from property schemas are aggregated into a default value in
the top level schema. Descriptions are however not yet aggregated.

Change-Id: Iaf46a9ecc83bee3566098c56137a1be66bff2ab9
2022-06-29 16:34:43 +10:00
DannyS712
32e99c3f19 ResourcesTest: fix typo $ilegalDeps
Added by yours truly in I5846f2c19b003989b56b12628b385fd37049483b

Bug: T201491
Follow-up: I5846f2c19b003989b56b12628b385fd37049483b
Change-Id: If2379b3819686ea14bfbd63202ec8e7c22c7bfce
2022-06-22 01:32:55 +00:00
Derick Alangi
d01e3ed739 Replace deprecated calls ParserOptions::newCanonical( 'canonical' )
This is a quick find & replace of calls to the deprecated method
ParserOptions::newCanonical() when the context is the string literal
'canonical'. This can be safely replaced by called newFromAnon().

Change-Id: If7bb68459b11e0c5f5de188f10fdae85ad1a78bf
2022-06-16 14:22:24 +01:00
Lucas Werkmeister (WMDE)
acae1c5107 Revert "phpunit: Default to vendor/bin/phpunit, remove suites.xml"
This caused unexpected problems with no obvious fixes. Needs more work.

This reverts commit 7238dff532.

Bug: T310255
Bug: T90875
Change-Id: I3758cbb6d0029b20ec1b0f67dbf2f422031c50ae
2022-06-09 14:15:54 +00:00
Kosta Harlan
7238dff532 phpunit: Default to vendor/bin/phpunit, remove suites.xml
* switch to phpunit.xml.dist instead of suites.xml
* switch composer.json to vendor/bin/phpunit
  * tests/phpunit/phpunit.php is retained but will be removed after CI
    jobs and other references on
    codesearch (https://codesearch.wmcloud.org/search/?q=tests%2Fphpunit%2Fphpunit.php&i=nope&files=&excludeFiles=&repos=)
    are removed
* add a default bootstrap.integration.php; unit tests in
  composer.json use the non-MW bootstrap file (bootstrap.php)
  * Migrate the phpunit.php logic into tests/phpunit/BootstrapIntegrationWrapper.php

Depends-On: I19d560bdcdb2ee914ab055e094841f2b5db8be55
Depends-On: Ib23209fc3b095e3c012ed84ce5c11f8b2d27b898
Co-authored-by: Daimona Eaytoy <daimona.wiki@gmail.com>
Bug: T227900
Bug: T90875
Change-Id: I82045c207738d152d5b0006f353637cfaa40bb66
2022-06-08 18:31:16 +00:00
daniel
ad11b034ab Settings: Generate schema artefacts using a single maintenance script
Previously, each of the four derived config schema files had to be
regenerated using a separate maintenance script. This change simplifies
regeneration by combining all for scripts into a single command that can
be used to regenerate all relevant files after changing
MainConfigSchema.

Change-Id: I7d38d8a4aede60475c4bdd0053d2e10e298b9843
2022-06-05 19:17:29 +00:00
Kosta Harlan
ff63886b0f
phpunit: Do not access MW services in dataProviders
We cannot access MW services in a data provider, as MW will not have
bootstrapped by this point in plain PHPUnit. And we do not want to
bootstrap MW by the time a dataProvider is executing, because unit tests
should not need (nor be able to access) MW services.

Change-Id: I21a5993f91b8fbe3fa476a8244b8911cf81e1d5f
2022-05-30 23:16:06 +02:00
Umherirrender
de47d93928 Get the MainConfig from MediaWikiServices instead of RequestContext
The getConfig of a ContextSource should only be used, if the
ContextSource is available. Getting the global context just for the
config looks harder to fix/inject as using the MainConfig from
MediaWikiServices

Change-Id: Iaf14bfc7bd68cc315672e1c256887faf87e22542
2022-05-24 21:54:21 +00:00
Tim Starling
3e2653f83b ResourceLoader namespace (attempt 2)
Move ResourceLoader classes to their own namespace. Strip the
"ResourceLoader" prefix from all except ResourceLoader itself.

Move the tests by analogy.

I used a namespace alias "RL" in some callers since RL\Module is less
ambiguous at the call site than just "Module".

I did not address DependencyStore which continues to have a non-standard
location and namespace.

Revert of a241d83e0a.

Bug: T308718
Change-Id: Id08a220e1d6085e2b33f3f6c9d0e3935a4204659
2022-05-24 15:41:46 +00:00
Amir Sarabadani
24115a8f4c Start clean up of revision_actor_temp table
It is being dropped in production

Bug: T215466
Change-Id: I66b2cb8653252e720c897351065978119f040ba7
2022-05-23 15:37:42 +00:00
jenkins-bot
df7b81e0e5 Merge "Settings: Add remaining schema info to config-schema.php" 2022-05-18 21:28:20 +00:00
daniel
e72b9d1ad6 Settings: Add remaining schema info to config-schema.php
By optimizing the structure of config-schema.php for fast loading,
some information needed for schema validation was lost. This patch
ensures that all schema information is retained in config-schema.php.

The code for consuming this field already existed, as written for
what we already output to the generated config.schema.yaml file.

Bug: T307769
Change-Id: I8adcdfd2b8fb5f5b96308eea74c07d8cc7a4d6ba
2022-05-17 22:16:29 +00:00
daniel
237bbf089f Turn DefaultSettings.php into a deprecated stub
DefaultSettings.php has been replaced by MainConfigSchema.
Loading DefaultSettings.php is deprecated.

Code that needs to have access to configuration defaults should use the
ConfigSchema service object.

Bug: T300129
Change-Id: I7b2c0ca95a78990be1cdb9dd9ace92f6dcf1af15
2022-05-17 16:50:56 +02:00
Lucas Werkmeister (WMDE)
a241d83e0a Revert "ResourceLoader namespace"
This reverts commit e08ea8ccb9.

Reason for revert: Breaks Phan in extensions, and as far as I’m aware,
this change isn’t urgently needed for anything, so the simplest fix is
to revert it again for now. After PHP 7.4 it should be safer to try this
again (we hopefully won’t need the two “hack” classes by then).

Bug: T308443
Change-Id: Iff3318cbf97a67f821f78e60da62a583f63e389e
2022-05-16 14:43:33 +00:00
Tim Starling
e08ea8ccb9 ResourceLoader namespace
Move ResourceLoader classes to their own namespace. Strip the
"ResourceLoader" prefix from all except ResourceLoader and
ResourceLoaderContext.

Move the tests by analogy.

I used a namespace alias "RL" in some callers since RL\Module is less
ambiguous at the call site than just "Module".

I did not address DependencyStore which continues to have a non-standard
location and namespace.

Change-Id: I92998ae6a82e0b935c13e02a183e7c324fa410a3
2022-05-16 14:41:27 +10:00
jenkins-bot
783a763bd2 Merge "AutoLoader: provide methods for registering classes" 2022-05-10 06:05:52 +00:00
daniel
37af531721 AutoLoader: provide methods for registering classes
This introduces static methods for registering classes and namespaces,
so we don't have to mess with global variables and static members
fields.

Bug: T240535
Change-Id: I1abb27bd70898d04c9253e0b7467447fa96d15a4
2022-05-10 13:55:53 +10:00
Aaron Schulz
774abe3ba6 Split out slow ScopeStructureTest for easier paratest parallelization
Change-Id: I677f27847e635003c932102b3876fcf81d270c88
2022-05-10 11:18:24 +10:00
Lucas Werkmeister
2e9fa547a1 Skip failing structure test in SettingsTest
This is blocking merges in several important extensions.

Bug: T307769
Change-Id: Ib33989dc38fe3a0dec59fbac949d4c732fa5d5d7
2022-05-06 16:09:56 +02:00
Aryeh Gregor
7b4b0135b9 Use str_starts_with/str_ends_with
All the other ways of doing it were ridiculous and much harder to read,
and usually required repeating the needle expression (to get its
length). I found these occurrences by grepping for various expressions,
but I undoubtedly missed some.

I didn't try replacing the many instances of strpos(...) === 0 with
str_starts_with(...), because I think they're readable enough as-is
(although less efficient). Likewise I didn't try porting strpos(...) !==
false to str_contains(...). For case-insensitive comparisons, Tim
Starling requested that we stick with substr_compare() because it's more
efficient than calling strtolower().

On PHP < 8 these functions will be included with a polyfill via
vendor/autoload.php. This is included at the beginning of
includes/AutoLoader.php, so if our autoloader has been included the
polyfill will be available. This means it should be safe to call these
functions from any code that would not be usable without our autoloader.

Three uses that Tim Starling identified as being performance-sensitive
have been split out to a separate commit for porting after the switch to
PHP 8.

Change-Id: I113a8d052b6845852c15969a2f0e6fbbe3e9f8d9
2022-05-02 10:59:58 +03:00
Aryeh Gregor
79fc95d39c Use MainConfigNames instead of string literals, #5
This should be the last of the usages in core, although I'm sure a few
are hiding somehow.

Change-Id: I7bf0b24bf23d3efb4c56a891830bbfe67945e899
2022-04-27 18:46:29 +03:00
lens0021
7798f184e8 phpunit: Support setting skin context in BundleSizeTest subclasses
BundleSizeTest is mainly used by skins to test the size of the modules
of the skin. Using default skin may cause unexpected results.

Bug: T305779
Change-Id: Id77c6124c9b1fd20633cda47bbca89f9b6724a63
2022-04-11 23:50:45 +00:00
Lucas Werkmeister (WMDE)
1aca74e298 Revert "Add SpecialPageFatalTest to @group Database"
This reverts commit be7565e3e1.

Reason for revert: Needed for a revert of CentralAuth change I3baf207711.

Change-Id: I847086a8ea2be8931b9f3fc092467445c47644a0
2022-03-31 12:37:57 +00:00
Taavi Väänänen
be7565e3e1
Add SpecialPageFatalTest to @group Database
This causes this test case to be run with sql_mode set to
STRICT_ALL_TABLES,ONLY_FULL_GROUP_BY, instead of the default TRADITIONAL
set in DevelopmentSettings. Many database pages (such as those including
a pager) make database connections when loaded without parameters.

If this can be merged without problems it would let us un-revert
Ic2729428297162763a772e6a16549ded8de06c01 too.

Bug: T304762
Change-Id: I3bb424ddcbd7d3d6c03ad23d071a69a94b7f5749
2022-03-26 15:43:46 +02:00
daniel
1137a357db phpunit: Revert "testConfigGeneration" structure test to simpler version
This was changed to support in-place updates of files,
but the idea which was since abandoned. So we can go back to
using stdout.

Change-Id: I825a00258c4f50244679fc47c81b6920dd241647
2022-03-24 14:57:47 +00:00
jenkins-bot
7894e49ea8 Merge "Generate config name constants." 2022-03-18 11:09:44 +00:00
jenkins-bot
18875c2c0f Merge "Generate DefaultSettings.php from schema" 2022-03-18 11:02:51 +00:00
daniel
6880561a4d Generate config name constants.
We can generate a class that contains constants for all config variable
names. This removes the need to rely on string literals when calling
Config::get, and it provides a place for documentation that integrates
better with IDEs than the markdown file.

Change-Id: I817dc14c4ce8fc0a29d9c07e8fd393c4f359cade
2022-03-18 10:32:58 +01:00
daniel
1ee8fde16b Generate DefaultSettings.php from schema
Avoid having to maintain defaults twice.

Change-Id: I7a883fe3c952cc653d43b7e399631ec3beab0bc3
2022-03-18 10:25:52 +01:00
jenkins-bot
29e0cf9c9d Merge "Use class constants to define config schema, rather than config-schema.yaml" 2022-03-18 07:44:45 +00:00
daniel
2fe23d6860 Use class constants to define config schema, rather than config-schema.yaml
Instead of maintaining the config schema as a yaml file, we
maintain it as a set of constants in a class. From the information in
these constants, we can generate a JSON schema (yaml) file, and an
php file containing optimized arrays for fast loading.

Advantages:
- PHP doc available to IDEs. The generated markdown file is no longer
  needed.
- Can use PHP constants when defining default values.

NOTE: needs backport to 1.38

Change-Id: I663c08b8a200644cbe7e5f65c20f1592a4f3974d
2022-03-17 21:20:03 +01:00
daniel
e239b02a5e Add convenience methods for asserting status.
This ensures that assertions work in a uniform way,
and provides meaningful messages in cause of failure.

Change-Id: Ic01715b9a55444d3df6b5d4097e78cb8ac082b3e
2022-03-16 22:44:25 +01:00
daniel
404f4a8512 Fix edge cases in schema validation.
Since PHP arrays make no clear distinction between lists (JSON arrays)
and maps (JSON objects), some edge case handling is needed to make
validation work reliably when we declare types for all arrays:

1) Allow array keys to be ignored, so an associative PHP array validates
as a JSON array. This is needed for the SessionProviders setting.

2) Allow associative arrays with numeric keys to validate as JSON
objects. This is done by ignoring the type validation when numeric keys
are detected. A warning is returned in the status object.

3) Work around validation failing on float values that are expected to
be integers. All numbers come from the yaml parser as floats, and the
"integer" type in JSON schema should accept floats with if the
fractional part is 0. But that doesn't seem to work, we need to cast the
values to integers explicitly.

Also, this fixes some mistakes in the schema: LockManagers is a list,
so it should use the JSON type "array". NamespacesToBeSearchedDefault
is a map (JSON object), even though it uses numeric keys. The Actions
registry is also a map.

Change-Id: I9d0453d740c377b7cce574df743536c39a0ec619
2022-03-08 13:59:19 +01:00
daniel
f31bc32a65 Remove deprecated alias $wgStyleSheetPath
$wgStyleSheetPath has been a deprecated alias for $wgStylePath since 1.3 (2004).
Time to get rid of it.

Change-Id: I78a6394003b9aefab7aa8559b8e2b22bc50154fc
2022-03-04 13:36:56 +01:00
Amir Sarabadani
8bbf64d563 tests: Make the error message of SettingsTest more informative
This would have saved me around an hour if I knew it earlier. Let's make
it not happen for others.

Change-Id: I2e146424fc01677383a15d98071d8cbc2d832d9b
2022-03-03 13:07:24 +01:00
Timo Tijhof
128debb64b tests: Change use of AtEase to at operator
Follows-up I361fde0de7f4406bce6ed075ed397effa5be3359.

Per T253461, not mass-changing source code, but the use of the native
error silencing operator (@) is especially useful in tests because:

1. It requires any/all statements to be explicitly marked. The
   suppressWarnings/restoreWarnings sections encourage developers to
   be "lazy" and thus encapsulate more than needed if there are multiple
   ones near each other, which would ignore potentially important
   warnings in a test case, which is generally exactly the time when
   it is really useful to get warnings etc.

2. It avoids leaking state, for example in LBFactoryTest the
   assertFalse call would throw a PHPUnit assertion error (not meant
   to be caught by the local catch), and thus won't reach
   AtEase::restoreWarnings. This then causes later code to end up
   in a mismatching state and creates a confusing error_reporting
   state.

See .phpcs.xml, where the at operator is allowed for all test code.

Change-Id: I68d1725d685e0a7586468bc9de6dc29ceea31b8a
2022-02-24 21:29:51 +00:00
Reedy
12aae45101 tests: Replace some usages of Wikimedia\(suppress|restore)Warnings()
Change-Id: I361fde0de7f4406bce6ed075ed397effa5be3359
2022-02-24 12:55:25 +00:00
daniel
f9b589f556 config-schema: Define types for all arrays.
This patch ensures that we know which arrays are lists (JsonSchema type
"array") and which are maps (JsonSchema type "object"). We can then
default to array_merge for lists and to array_plus for maps. This seems
clearer than requiring an explicit merge strategy to be declared for all
arrays.

This patch specified a mergeTrategy for some config variables that need
behavior different from the default.

This patch also changes the merging behavior to allow non-array values
to replace arrays and vice versa. It also changes the behavior of
defaults to allow falsy values to override non-falsy defaults.

Bug: T300129
Change-Id: Ia7b0c0250af6a957eac1efb554fb47511f5e093f
2022-02-23 14:09:41 +01:00
mainframe98
de0c4819d1 Add validation for abstract schema
This adds an option to the schema generating maintenance scripts to
validate abstract schemas and schema changes and a structure test to
validate exisiting schemas and schema changes. Schemas are also
validated when generating.

The validation for the schema doesn't impose limits on table, index or
column names as I couldn't find any reliable conventions for them.

The structure tests only cover MediaWiki itself as there is no
convention on where extensions store their abstract schema.
Ideally, auto detection would be possible for sql/, but for now
extensions have to define their own (thankfully trivial) tests.

A couple of invalid definitions were fixed thanks to these tests.

I aimed to be thorough, but not all parts of the abstract schema
are completely clear, and Doctrine's documentation is not complete.
As a result, not everything has a description field.

Bug: T298320
Change-Id: I681d265317d4d1584869142ebb23d4098c06885f
2022-02-22 17:41:08 +00:00
Petr Pchelko
ef73bfafd9 Add simple configuration doc generator
This is a first draft of the configuration doc renderer.
The resulting markdown certainly needs some love, but
we can work on improvements incrementally. This gives
us a baseline to reference on doc.wikimedia.org

Bug: T296647
Change-Id: I3c426b9fc37b1cf7ce8423969b2d7589767ee6cc
2022-02-09 07:09:32 -08:00
daniel
f5641f9856 Do not rely on $IP in DefaultSettings.php
In order to allow configuration default to come from JsonSchema,
and dynamic defaults need to be initialized in Setup.php.

This movesd the initialialization of $wgExtensionDirectory and $wgStyleDirectory
to Setup.php

Bug: T294788
Change-Id: I11f5723aa299caa210cf6a1f5b7436f191b1ffc2
2022-02-03 22:05:34 +00:00
Petr Pchelko
d54e3d216c Add pre-generator for config-schema.php
Bug: T300129
Change-Id: Ib2620993114af5a659bda60dc45b6fb3bed657b0
2022-02-03 13:27:47 +00:00