Commit graph

44 commits

Author SHA1 Message Date
Reedy
75640200fb tests: Namespace api tests
Bug: T357823
Change-Id: I0d7cc2c9b166d5e5b913c1305f7cee017fe377af
2024-02-18 15:47:04 +00:00
Reedy
85396a9c99 tests: Fix @covers and @coversDefaultClass to have leading \
Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
2024-02-16 22:43:56 +00:00
Matěj Suchánek
45390a52eb Clean up tests
Replace strpos with str_contains, str_starts_with, etc.
Fix spelling of "cannot" and other typos.

Change-Id: Ie52900b323f46d1978a9dd9ea3b17619b8942160
2024-02-12 09:25:25 +01:00
Umherirrender
da3301cb08 tests: Remove unneeded return from closures
Change-Id: Icdfdf8e1db69f5294349536590269b3490ef87b7
2024-01-27 00:07:36 +01:00
Reedy
627ad6956d ApiSiteInfo: Add siprop=autopromoteonce
Bug: T196059
Change-Id: Ia41b55a1da13e14f633cb32ee8efcc2b4ff88cee
2024-01-24 20:31:48 +00:00
星耀晨曦
9ca8844902 ApiSiteInfo: Add siprop=autopromote to return $wgAutopromote data
Bug: T196059
Co-Authored-by: Reedy <reedy@wikimedia.org>
Change-Id: I92236cea845c10ef1725891a49d48a04d5d3bfad
2024-01-24 20:14:05 +00:00
Reedy
72df6cb8da libs/composer: Namespace under Wikimedia\Composer
Change-Id: I5ffedacf31e60fb0f38e308f8dcf010e577f919e
2024-01-13 20:10:25 +00:00
James D. Forrester
4ed5ca48b1 Follow-up 71ff05267: Stop writing to tablesUsed in tests, now unnecessary
Bug: T342301
Change-Id: I5ea01f7ee103570165261bde0965c5b65e04c369
2023-11-21 09:02:48 -05:00
Martin Urbanec
c9908da103 IP Masking: Expire temporary accounts in 1 year
Why:
Temporary accounts (introduced as part of IP Masking)
are supposed to expire 1 year after their registration.
Automatic account expiration can be done via a maintenance
script, which would be periodically executed via cron / systemd.

Make it possible for extensions to provide their own logic
for generating a list of temporary accounts to invalidate.
This is used in CentralAuth to base registration timestamp
on the global registration timestamp.

The default behavior is "temporary accounts do not expire",
given the feature requires a maintenance script to run
periodically, which will not be the case on third party
instances.

What:
* Add `expireAfterDays` to $wgAutoCreateTempUser, controlling
  how many days temporary accounts have.
* Add UserSelectQueryBuilder::whereRegisteredTimestamp(),
  filtering accounts based on user_registration.
* Add ExpireTemporaryAccounts maintenance script, which is
  @stable to extend.

Bug: T344695
Change-Id: If17bf84ee6620c8eb784b7d835682ad5e7afdfcc
2023-11-09 15:11:48 +01:00
Amir Sarabadani
cd2e19c050 tests: Use $this->getDb() instead of wfGetDB() in integration tests
Deprecated long time ago.

Bug: T330641
Change-Id: Ia57f12d350c3346029aafae25534c9ed262a7e98
2023-09-25 21:08:09 +02:00
Daimona Eaytoy
4c72c161d8 Deprecate MediaWikiIntegrationTestCase::$users
This property shouldn't be needed in modern code, where most things can
use Authority. So much so because TestUser adds a dependency on the
database, but many tests that use TestUser don't even need the database.
ApiTestCase, in particular, sets this property in setUp, thus adding a
database dependency to all API tests, including those that don't need
users or the database at all.

Deprecate the property and replace existing usages in core. The one in
ApiTestCase is much harder to migrate, but this patch replaces the array
with an anonymous ArrayAccess class to allow lazy initialization and
remove DB dependencies.

Bug: T155147
Change-Id: I59c4ed1f6a7572d3a92387b15b8e56625bc376a2
2023-07-25 12:12:43 +00:00
thiemowmde
8a9dd67139 Avoid calling overrideConfigValue() multiple times
Same as I7a82951.

overrideConfigValue() and overrideConfigValues() both call
setMwGlobals(), which calls resetServices(). This is surprisingly
expensive. It's much better to call it once with an array.

Change-Id: I4ff2f6b902b1a1e0b554ce6fc76f3b612f703fae
2023-07-20 14:59:42 +02:00
James D. Forrester
357f408c13 tests: Replace deprecated calls to wfExpandUrl with hard-coded url
Bug: T319340
Change-Id: Iae13352f0cc902f74eb4c918dbb1a451472b0985
2023-06-23 17:23:18 +00:00
Umherirrender
792981fea5 tests: Use Title::makeTitle instead of Title::newFromText
Avoid parsing known titles in tests to improve performance

Change-Id: Iddefe62c3d85281642f17e60cbc27aff47b85a67
2023-06-19 21:54:57 +02:00
Umherirrender
d36073cdcf tests: Make some PHPUnit data providers static
Initally used a new sniff with autofix (T333745),
but some provide are defined non-static in TestBase class
and need more work to make them static in a compatible way

Bug: T332865
Change-Id: I889d33424f0c01fb26f2d86f8d4fc3de3e568843
2023-05-20 01:05:27 +02:00
Bartosz Dziewoński
77927cc2fa Expose automatic temporary user info in the API
action=query&prop=info&intestactions=...:
  Add &intestactionsautocreate=1 to also check whether the actions
  would result in a creation of a temporary user account.

action=query&meta=siteinfo:
  Add &siprop=autocreatetempuser to output the configuration
  of temporary user accounts.

Bug: T335532
Change-Id: I62b4bb630decac92cbb8c7ddf00307df0dadb516
2023-04-28 01:42:59 +02:00
Amir Sarabadani
e182010622 Reorg: Move SiteStats*.php to SiteStats/
It's going to be a bit small and narrow but it's better than sitting in
the root of includes/ plus I hope we can hollow out SiteStatsUpdate
class into the third one and or move this under a better directory in
the future.

Bug: T321882
Change-Id: Ia503b53b31ca00600f8c18b61a2652c3e146494e
2023-04-27 01:16:29 +02:00
Bartosz Dziewoński
1048db795b API tests: Assert error codes, not error messages
Error messages are not guaranteed to be stable, and these tests
prevent us from improving them.

Error codes are supposed to be stable, so we should be asserting
that they do not change (especially since many of them are
dynamically generated by the dodgy code in ApiMessageTrait).

Introduce helpers assertApiErrorCode() and expectApiErrorCode()
to be used instead of the usual PHPUnit assertions/expectations
for this case.

Change-Id: I752f82f29bf5f9405ea117ebf9e5cf70335464ad
2023-04-26 19:36:29 +02:00
Tim Starling
be3018b268 Just another 80 or so PHPStorm inspection fixes (#4)
* Unnecessary regex modifier. I agree with this inspection which flags
  /s modifiers on regexes that don't use a dot.
* Property declared dynamically.
* Unused local variable. But it's acceptable for an unused local
  variable to take the return value of a method under test, when it is
  being tested for its side-effects. And it's acceptable for an unused
  local variable to document unused list expansion elements, or the
  nature of array keys in a foreach.

Change-Id: I067b5b45dd1138c00e7269b66d3d1385f202fe7f
2023-03-25 00:39:06 +00:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
C. Scott Ananian
310d335136 Improve ApiQuerySiteInfo handling of deprecated and "extra" language links
Fix documentation related to ExtraInterlanguageLinkPrefixes
configuration: it should be a list, not a map, and described usage
better.

In ApiQuerySiteInfo, third-party clients (like Parsoid) need to know
whether a given language link core corresponds to a deprecated
language code or a "real" one; the API was also missing information
regarding which language code an "extra language link" prefix
corresponds to (given by InterlanguageLinkCodeMap in the
configuration).

Finally, add the corresponding bcp47 codes for these interlanguage
links, so third-party clients don't need to know details of mediawiki
internal and deprecated language codes.

Change-Id: I82465261bc66f0b0cd30d361c299f08066494762
2023-02-09 16:27:24 +00:00
Umherirrender
ed33ab1bbf tests: Replace deprecated Language::(has|get)Variants
Bug: T252095
Change-Id: Ie95c1343edf980b62693752c82b6009e744edaea
2023-01-31 21:19:21 +00:00
Umherirrender
e89b68d28d tests: Replace deprecated User::getAllGroups
Bug: T275148
Change-Id: I24e864e2d953ed01e4076a9c57496e3c37b20d8b
2022-12-21 18:55:09 +01:00
daniel
477c8952fe HookContainer: add getHookNames method
This proves a way to list all active hooks.
ApiQuerySiteInfo was relying on $ghHooks, which does not contain hooks
that were registered by extensions using the new hook handler system.

Change-Id: Ifae205f22ab4cc7ae0dfd15e994a1921af51b05c
2022-11-16 11:54:39 +00:00
daniel
8c1c1ae35a Enable pig-latin variant for testing
Having pig-latin enabled per default in dev environments is convenient
for manual testing. More importantly, it will allow us to write
end-to-end tests for variant conversion.

Depends-On: I9dc2f743ac487b0f7cfb667150c0f6950d5e7fce
Depends-On: I85b66c85be3959d48a048733af17197bc4cf70af
Change-Id: Ia80ad33cbf5e311fa8b84bd765a8df8d156f4c38
2022-11-08 17:45:51 +05:30
Thiemo Kreuz
68ec2661d2 Use native array_column() in tests instead of loops
It's just a nice, lesser known convenience function. Exists since
PHP 5.5.

The changes to SerializationTestTrait ended being a little different.
Original I tried to use array_column() as well. But it drops the
array keys, which is relevant here.

We found that calling the two methods getTestInstances(AndAssertions)
multiple times is quite expensive and should be avoided. I changed
the code slightly so it's much less likely this is done unintentionally.

Change-Id: Ifaba3c370871a7c97b4d81ec21ff6ec134433fc0
2022-08-16 15:41:14 +02:00
Umherirrender
dee77e59a1 tests: Remove resetServiceForTesting after overrideConfigValues
overrideConfigValues is documented to reset services as well

Change-Id: Ie13a699f6cd912b912d34adb97704bab3cbdff2d
2022-07-27 23:08:27 +02:00
Derick Alangi
86d4a253e7 tests: Migrate setMwGlobals() to overrideConfigValue(s)()
Directories covered are: /api/, /auth/ and /block/, more to come.

Change-Id: I9dfb0773cbfff36cba7389ed2d9b3c7b1b22612e
2022-07-19 15:42:15 +01:00
Thiemo Kreuz
3703b30618 Tests: Use createNoOpMock() shortcut in a few more places
… instead of doing the same manually with anythingBut() and such.

Change-Id: Idb66040d1560a82df9a5bfa2a6c7e20a0649e49c
2022-07-18 21:25:31 +00:00
Reedy
41c42d5435 Tests: Cleanup some unnecessary nested function calls
Replace ->will( ->return with ->willReturn(

Change-Id: Ia2dfafa03cac8169d86d6fa5a30b73bfad1fe9fa
2022-06-06 01:02:34 +01:00
Umherirrender
770f905900 tests: Use namespaced IDatabase class
Change-Id: I7171ff26faee00d9eaabc33c2f3d91049ea0b40d
2022-05-28 00:09:55 +02:00
Aaron Schulz
3960005202 ApiQuerySiteinfoTest: Don't access MW services in dataProvider
Bug: T297292
Change-Id: Ib310b83d26f2badb628965c62f7ca4caf1414e5b
2022-03-07 21:57:59 +00:00
Alexander Vorwerk
decbaf4f38 phpunit: use ->getServiceContainer() in integration tests
Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
2022-01-27 22:04:16 +01:00
Kosta Harlan
0c2cc804e1 phpunit: Use is_file/is_dir instead of file_exists
Yes, it's a micro-optimization. See https://bugs.php.net/bug.php?id=78285
and https://thephp.cc/articles/caching-makes-everything-faster-right
for more info.

Change-Id: Ib8e8e9794e15066476f35cdb1236df8b983274d6
2022-01-03 21:47:56 +01:00
Reedy
8c39aab84b Remove or replace usages of "sanity"
Bug: T254646
Change-Id: Ib192dc5704a14d02c7c374d0ab29bac55c5df24a
2021-11-21 19:35:49 +00:00
Bartosz Dziewoński
b1b1ec343f ApiQuerySiteinfo: Fix "rightsinfo"/"url" when $wgRightsPage is set
Bug: T295191
Change-Id: I181b29dbdc8374837789c1d900577e49f62bd8d3
2021-11-05 21:56:01 +01:00
Ammarpad
1cf4eab3ab ApiParse: Support hidden skins
Since $wgSkipSkins is meant to only 'remove skin from preferences',
it should not affect parsing with them.

So these skins need to be allowed here.

To achive this, this patch adds getInstalledSkins() method to SkinFactory
to provide the complete. The method supersedes getSkinNames() which does
the same thing but with ambiguous name.

Description of getAllowedSkins() has been corrected as it was slightly incorrect.

Bug: T237856
Change-Id: I0889b823d27f1a2830cc0205f5a21ed4de744e08
2021-09-20 09:29:24 +01:00
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
Timo Tijhof
b281e3e059 api: Fix unstable ApiQuerySiteinfoTest case relying on default settings
This test failed by default in mediawiki-docker-dev or on any other
more (production-like) set up with a protocol-relative $wgServer value.

It passed in CI where it is set to `http://localhost:9412`.

The test also failed when $wgFileExtensions contained additional
entries for any reason.

Fix both of these tests by simplifying their needless inheriting of
live "current" settings and just set them to explicit example values
and them assert the way the code should behave for those values.

Follows-up 27d41f442a.

Remove use of wfExpandUrl() to formulate the "expected" value.
Expected values that are dynamic are an anti-pattern and greatly
decrease confidence in, and self-documenting value of, a test.

Change-Id: I6f7b8d89767ed8eaacbc615a9f22a3b357a6dd58
2021-05-20 18:55:15 +00:00
James D. Forrester
df5eb22f83 Replace uses of DB_MASTER with DB_PRIMARY
Just an auto-replace from codesniffer for now.

Change-Id: I5240dc9ac5929d291b0ef1c743ea2bfd3f428266
2021-04-29 09:24:31 -07:00
Peter Ovchyn
45140daa29 Avoid using User ::getDefaultOption, ::getDefaultOptions
This patch hard-deprecates the methods above

Bug: T276035
Change-Id: Ic36b0702f7547acce0d162d6e0b54bbd4ecf4d81
2021-03-16 17:24:17 +02:00
Umherirrender
a1de8b8700 Tests: Mark more more closures as static
Result of a new sniff I25a17fb22b6b669e817317a0f45051ae9c608208

Bug: T274036
Change-Id: I695873737167a75f0d94901fa40383a33984ca55
2021-02-09 02:55:57 +00:00
Reedy
729f20afc8 Tests: Mark more closures as static
Bug: T274036
Change-Id: I911d3041cebe417d162934223b46ea295c6d20e3
2021-02-07 13:26:56 +01:00
Aaron Schulz
815912062f Move ApiQuery* tests under the /query subdirectory
Consistency aside, this is useful for grouping more tests
into separate threads when using directory based suites.

Bug: T50217
Change-Id: Ife9acd5990c4ae4a5fc18371559e93d7d86fb57d
2020-10-30 03:31:12 +00:00
Renamed from tests/phpunit/includes/api/ApiQuerySiteinfoTest.php (Browse further)