Commit graph

193 commits

Author SHA1 Message Date
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
Tim Starling
5e30a927bc tests: Make some PHPUnit data providers static
Just methods where adding "static" to the declaration was enough, I
didn't do anything with providers that used $this.

Initially by search and replace. There were many mistakes which I
found mostly by running the PHPStorm inspection which searches for
$this usage in a static method. Later I used the PHPStorm "make static"
action which avoids the more obvious mistakes.

Bug: T332865
Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
2023-03-24 02:53:57 +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
Martin Urbanec
80bf808bb6 ApiQueryLanguageinfoTest: Do not pass a float to setFakeTime
ConvertibleTimestamp::setFakeTime is documented to
only take callbacks returning an int. ApiQueryLanguageinfoTest
violated this expectation, resulting in test breakage
(see I06c625abe351b2f189f5dbf6f331d34bb56004b2).

To get some integers to chose from, bump MAX_EXECUTE_SECONDS
to three.

Bug: T329609
Change-Id: I82d49a5e3a52c14dbd7e5324eb4c75cf7c33f3d2
2023-02-14 11:53:42 +00: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
6a8b794779 tests: Replace deprecated User::idFromName
Bug: T325687
Change-Id: I4082ddc9039e8335ceab354f34f3b3ae674407c7
2023-01-09 18:25:56 +01:00
Umherirrender
e89b68d28d tests: Replace deprecated User::getAllGroups
Bug: T275148
Change-Id: I24e864e2d953ed01e4076a9c57496e3c37b20d8b
2022-12-21 18:55:09 +01:00
Umherirrender
fd516a98e1 Fix whitespaces after comma
Change-Id: Ide6de0a53661e6f650099d7b1f274a02699441df
2022-12-15 01:24:14 +01:00
daniel
c6ca5baa16 phpunit: improve isolation by calling User::clearInstanceCache
User objects may hold references to service objects. They need to be
reset when services are reset between and during tests.

Change-Id: I7fe767977f1fe01d508fddf7a92ade3ec8ba2662
2022-12-04 15:21:30 +01:00
jenkins-bot
a94b359376 Merge "Implement LanguageConverter for sh.wiki" 2022-11-24 22:28:46 +00:00
jenkins-bot
614e496345 Merge "HookContainer: add getHookNames method" 2022-11-21 01:48:02 +00:00
Máté Szabó
b523ab0081 Parser: Fix extractSections() behavior for PHP >= 8.0
PHP 8.0 changed the behavior of numeric comparisons such that
non-numeric strings no longer weakly equal 0.[1] This breaks the logic
in Parser::extractSections(), which was relying on the old comparison
behavior for section indexes and in turn causes the revisions API to
return a bogus 'nosuchsection' for error when called with rvsection=new.

Fix the logic by explicitly casting the section index to a number, which
will yield the appropriate numeric section index for a numbered section
index and 0 for a non-numeric section index (like 'new'). Also add test
cases for the relevant API module.
--
[1] https://wiki.php.net/rfc/string_to_number_comparison

Change-Id: If32aa4d575cff66bd4eee56f9e3b0b0d9ba04fde
Bug: T323373
2022-11-18 15:23:46 +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
Acamicamacaraca
a573bea01b Implement LanguageConverter for sh.wiki
This patch will implement a one-way transliterator (Latin->Cyrillic), per community consensus.

Bug: T268033
Change-Id: I6f3e7efe3630e9960584dca3a5ee55cb92ea722c
Co-Authored-By: Deni <deni@deni.dk>
Co-Authored-By: Winston Sung <winston21.sung@gmail.com>
2022-11-15 06:29:11 +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
Máté Szabó
f15e0a62f9 ApiQueryRevisionsBase: Fix 'rvdiffto' parameter handling on PHP 8.0
The legacy 'rvdiffto' API parameter allows consumers to supply a
revision ID or the special strings 'cur', 'prev', 'next' to
revision-related API modules. This will then be resolved to a revision
and the diff of returned revisions against this revision will be
attached to the response.

On PHP 8.0, this parameter is broken as 'cur', 'prev', 'next' no longer
get resolved to the appropriate revision ID but rather are treated as
invalid literal revision IDs. This is because given an associative array
`$params = [ 'diffto' => 'prev' ];`, the expression `$params['diffto']
!= 0` is false on PHP < 8.0 but true on PHP >= 8.0.[1]

Fix it by also checking whether the parameter value is numeric before
treating it as a revision ID, and add a test case for this logic. To
facilitate testing, convert the counter used by ApiQueryRevisionsBase to
count the number of uncached diffs served in the current response to an
instance variable; it is currently a static variable which persists
across test boundaries.

Change-Id: Ifbe14cd2880c98dddc5577d226bef5878bdd657f

---
[1] https://onlinephp.io/c/81e7b

Bug: T322335
Change-Id: Id5032932842c94f4d3ca3707fbc733f5b9704151
2022-11-03 15:49:04 +01:00
Amir Sarabadani
bbe704b5c1 Reorg: Move some of request related classes to MediaWiki/Request
Redoing I5ea70120d74 but without moving WebRequest that caused issues
with phan-taint-plugin.

Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequestUpload

Bug: T321882
Change-Id: I832b133aaf61ee9f6190b0227d2f3de99bd1717b
2022-10-28 10:15:31 +00:00
Zabe
f6b9381d7f Revert "Reorg: Move some of request related classes to MediaWiki/Request"
This reverts commit 2bdc0b2b72.

Reason for revert: T166010#8349431

Bug: T166010
Change-Id: Idcd3025647aec99532f5d69b9c1718c531761283
2022-10-27 13:14:16 +00:00
Amir Sarabadani
2bdc0b2b72 Reorg: Move some of request related classes to MediaWiki/Request
Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequest
 - WebRequestUpload

Bug: T166010
Change-Id: I5ea70120d745f2876ae31d039f3f8a51e49e9ad8
2022-10-26 16:49:10 +02:00
Tim Starling
0077c5da15 Use short array destructuring instead of list()
Introduced in PHP 7.1. Because it's shorter and looks nice.

I used regex replacement.

Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
2022-10-21 15:33:37 +11:00
Func
b5f3400c27 ApiQueryLanguageinfo: Allow fetching variant names from API
Variant names is stored in 'variantname-xx' messages and different from
language names.

Bug: T302200
Change-Id: If1b16f12a6867de7caa9a28e0370745780006bec
2022-10-05 14:35:40 +00:00
Umherirrender
89b2d11a0d tests: Use Title::makeTitle instead of Title::newFromText
Avoid parsing known titles in tests to improve performance

Change-Id: Ie240eb42479d19714e64cc4606e26073fadc2e13
2022-09-23 21:53:11 +02:00
jenkins-bot
12fb8ac58d Merge "Add cancreateaccount property to userinfo API" 2022-09-12 06:54:26 +00:00
Umherirrender
6555923b08 tests: Replace deprecated WikiPage::factory
Bug: T297688
Change-Id: Ic84d491c5603f3590e26cb56a305508b2b0ca109
2022-09-02 19:34:02 +00:00
Gergő Tisza
0024c71954 Add cancreateaccount property to userinfo API
Add a new action=query&meta=userinfo&uiprop=cancreateaccount
API property that checks whether the current user is allowed to
create accounts. This replaces the functionality removed from
list=users&usprop=cancreate in Ie94d61640301192b287275311f345,
and makes more sense - list=users is supposed to be about the
username (and re-called every time the username in the
registration form is changed), while meta=userinfo is about the
current user. It's also more accurate: it checks for all things
integrated with the permission system.

Change-Id: I0006500245a7c2bc3be0310ce9860b5771637a29
2022-08-31 11:51:18 +00:00
jenkins-bot
c17df8ff78 Merge "tests/api: Add TestUser::getAuthority and use it" 2022-08-19 16:35:47 +00:00
jenkins-bot
706d479075 Merge "tests/api: Use MediaWikiIntegrationTestCase::editPage for edits" 2022-08-19 16:35:40 +00:00
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
ef0623ec06 tests/api: Add TestUser::getAuthority and use it
Change-Id: Icfb66f9927c8e67582010a208538b0b5e0ba353f
2022-08-06 23:15:27 +02:00
Umherirrender
6a8f3b4c55 tests/api: Use MediaWikiIntegrationTestCase::editPage for edits
Also improve MediaWikiIntegrationTestCase::editPage by accepting
LinkTarget objects and use services instead of static functions

Change-Id: I3d036b0837f212d3500159c1d3a3daa4e706882c
2022-08-06 22:21:51 +02:00
Umherirrender
a76ed60462 watcheditem: Replace deprecated User::getOption
Bug: T296083
Change-Id: I703036d64006fed363cbe93040b928287a4530bd
2022-08-05 22:31:09 +00: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
jenkins-bot
8de0be85a4 Merge "Step 1 of renaming sr-ec and sr-el to sr-cyrl and sr-latn" 2022-07-20 22:31:39 +00: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
Fomafix
6839b85994 Step 1 of renaming sr-ec and sr-el to sr-cyrl and sr-latn
The language codes sr-ec and sr-el are not conform to BCP 47.
BCP 47 explicit mentions sr-Latn and sr-Cyrl as examples.

This change adds support for the language codes sr-cyrl and sr-latn
as fallback languages of the language codes sr-ec and sr-el. This
allows to rename the message files and the system messages without
changing the language codes yet.

The next step is to rename the language codes in Translatewiki as
described in https://translatewiki.net/wiki/Renaming_language_codes
Also local system messages in MediaWiki:*/sr-ec and MediaWiki:*/sr-el
can moved to MediaWiki:*/sr-cyrl and MediaWiki:*/sr-latn.

The final step is the change I75da0af35a2066e7963e50c56c99daf1e07c55e6
to complete the rename of the language codes.

Bug: T117845
Change-Id: I666fbdea89ccf21aab6ca1849adf22813dec052e
2022-07-10 21:19:34 +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
Lucas Werkmeister
47f598b94b Use continuation when meta=tokens doesn’t fit in response
The implementation and test are both based on similar code for
meta=siteinfo. I’ve checked manually that, when no continuation is
necessary, the output looks the same as before in all formats, despite
the different way that we now set it.

Bug: T309921
Change-Id: I3b4b7aecdeb6461ae5bd8dc188e5ba49a119858e
2022-06-04 17:43:38 +02:00
Umherirrender
770f905900 tests: Use namespaced IDatabase class
Change-Id: I7171ff26faee00d9eaabc33c2f3d91049ea0b40d
2022-05-28 00:09:55 +02:00
lziad
f54940b412 API: Add IP range support to list=usercontribs
This works by using the ip_changes table.
`iprange` parameter is introduced in order to restrict input to only one range.
Result is sorted by name, timestamp similar to `userprefix` parameter,
and T180153 (sort by timestamp first) is not addressed.

Related messages and test cases are added.

Bug: T177150
Change-Id: I3b8a917aaa76e18decf85b621dc77799698e4a77
2022-05-25 00:03:08 +00:00
Umherirrender
2909d06a08 Use new namespace for revision related classes
All revision related classes are namespaced MediaWiki\Revision
instead of MediaWiki\Storage since 1.32. The old namespaced
class names are deprecated and only kept for backwards-compatibility.

Bug: T305784
Change-Id: I34e492d84d9fc4bc78481667202716d93b3c43cb
2022-04-14 23:03:43 +02: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
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
jenkins-bot
fd84c0f087 Merge "tests: Replace usages of deprecated WikiPage::doDeleteArticleReal" 2022-01-27 19:32:06 +00:00