Commit graph

922 commits

Author SHA1 Message Date
jenkins-bot
9f84096300 Merge "Convert PageEditStash to PageIdentity/UserIdentity" 2021-04-16 22:29:31 +00:00
Daimona Eaytoy
535d7abf59 phpunit: Mass-replace setMethods with onlyMethods and adjust
Ended up using
  grep -Prl '\->setMethods\(' . | xargs sed -r -i 's/setMethods\(/onlyMethods\(/g'

special-casing setMethods( null ) -> onlyMethods( [] )

and then manual fix of failing test (from PS2 onwards).

Bug: T278010
Change-Id: I012dca7ae774bb430c1c44d50991ba0b633353f1
2021-04-16 20:15:00 +02:00
Petr Pchelko
1f11b88f35 Convert PageEditStash to PageIdentity/UserIdentity
One tricky piece left when we get the Request from user
to check whether it was posted, needs a more thorrow
investigation.

Depends-On: Iab96a35be8f50fdbc66194bd8956d98b5b6b0032
Change-Id: I7164b914299441bd0f82e764252c8b5d30b45fbe
2021-04-14 09:12:04 -07:00
Umherirrender
cfcb3e4785 Use ::class for class name
This works also for non-existing classes,
because it is resolved on compile time

Change-Id: Id3132341856fb1eb20e8b494bb4acdfe3a394db6
2021-04-08 21:17:42 +02:00
jenkins-bot
09d103fa49 Merge "API: Clean up ApiPurgeTest" 2021-04-04 21:08:51 +00:00
Cindy Cicalese
a78184782f Convert WatchedItem et al to PageIdentity
Change-Id: Iddcd109b7f78efdbcb0e4016e81fd2c8d4666b46
2021-03-26 15:51:19 -04:00
DannyS712
d5d2f64dcf ApiCSPReportTest: remove unneeded setMwGlobals()
Called with "CSPFalsePositiveUrls" instead of
"wgCSPFalsePositiveUrls", so not currently changing the
actual global that matters, and since the test is passing
as-is no need to fix, we can just remove

Change-Id: I1b599bc0f7eff05e3ca68e1a0a326264a192bdd7
2021-03-24 17:28:43 +00:00
Daimona Eaytoy
5aa88425b5 ApiBlockTest: fake the current time to avoid flaky tests
ConvertibleTimestamp::setFakeTime is the standard for this kind of
tests. This specific test just caused
f069704e517f749f3fd7de0f6e801c145e6cfab1 to fail the merge-and-submit,
which delayed other merges too.

Change-Id: I3fc92923fee7148f3b3dce610cdb21b1712c9982
2021-03-22 17:57:00 +01: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
DannyS712
25ade27632 Remove unused tests/phpunit/includes/api/words.txt
Follow-up: Iec1d89324ff2fa53d1712796157adaf4ed34bdfe
Change-Id: I84a2595797b024a36f7db69963b589851bf30c1a
2021-03-14 20:52:36 +00:00
Timo Tijhof
e88f4ca293 API: Clean up ApiPurgeTest
Follows-up 5e6cccc3a4.

- Let PHPUnit do the diffing instead of exporting expected value
  into the description.

- Use a stricter and complete assertion of the result, not just
  one key existence only. Specifically, this means the value (true)
  is asserted, and any additional or unexpected properties result in
  failure. For example, if all of them were marked as missing+invalid
  the old test would pass as it wasn't checking absence. In general,
  assertArrayHasKey() is almost always indicates a lax test that can
  be improved, or a redundant assertion (such as here, where it was
  used to check 'purge' exists before use, but PHP and PHPUnit naturally
  validate that already).

Change-Id: Ie7067633e4df0b9a1b451ce4c53a98e8ee3c3ae7
2021-03-13 02:29:09 +00:00
DannyS712
24afc63e49 Remove constructors from test classes
Tests should put their setup code in ::setUp(),
rather than __construct

Change-Id: I622f017f3c78a72acc65310f37d61dbec2a5da79
2021-03-08 03:31:25 +00:00
jenkins-bot
245bb6234f Merge "Make ApiWatchlistTraitTest a pure unit test" 2021-03-01 10:09:27 +00:00
DannyS712
63363c2509 Make ApiWatchlistTraitTest a pure unit test
We can use mocks :)

Change-Id: Ic0ca07191598e22741a14bb7f0d8f08fe4c98e41
2021-02-26 22:58:28 +00:00
DannyS712
bab2c0099c Make ApiModuleManagerTest a pure unit test
Switch test case with services to use a
service other than ObjectFactory, to make
it easier to mock.

Change-Id: I374a516b6bcc8111b2432245faf935f8287d45a7
2021-02-26 22:41:46 +00:00
Cindy Cicalese
f6e1891c6f Use Authority and GroupPermissionLookup in Action API
Replaces calls directly to PermissionManager with calls to
the Authority object available from Context or the
GroupPermissionLookup service.

This patch does not address use of PermissionManager for
blocks.

Deprecations:
- ApiBase::checkUserRightsAny deprecated passing optional
User parameter
- ApiBase::checkTitleUserPermissions deprecated passing
LinkTarget as first parameter, takes PageIdentity instead

Bug: T271462
Bug: T271854
Change-Id: I5d7cac1c28a37e074750c46cda03283980a07fca
2021-02-23 14:31:14 +00:00
Thalia
208e828a1f Pass linkable user name in Special:Preferences "Account data" help text
For the optional message in the "Account data" section, introduced in
d4357d621f.

Passes the user name escaped with underscores, so that links can be
built correctly in the message translation.

This means we have to expand yet further the list of User methods called
in ApiOptionsTest, but so be it.

Bug: T272412
Change-Id: Ia1c135144763db9e92f1b555f009229bd1a9d3c8
2021-02-16 16:53:37 -08:00
jenkins-bot
5ea464b234 Merge "Use static closures where safe to use" 2021-02-14 23:05:48 +00:00
Timo Tijhof
8fca24fdc1 API: Fix flaky ApiQueryInfoTest case
The timestamp in the year 3030 was presumably chosen so as to
always be in the future (since expiry in the past would be ignored).
However, while seemingly clever, this backfires because it gets
shrunk by the default wgWatchlistExpiryMaxDuration value to some
time in August 2021, around the "current" time of day.

And "current" generally is thought of as moving forward at a rate
of 1s/s, bending of spacetime notwithstanding. Thus the test would
sometimes fail in ways such as:

> 1) ApiQueryInfoTest::testExecute
> Failed asserting that two strings are identical.
> --- Expected
> +++ Actual
> @@ @@
> -'2021-08-13T01:23:19Z'
> +'2021-08-13T01:23:18Z'

Fix this by using a mock current time, paired with a suitable
max duration and expiry value.

Also fix some of the other asserted values to not be reflections
of the source code but actually explicit assertions (at least the
details that we know to be constant, given the environment ensured
by ApiTestCase and MediaWikiLangTestCase). This reduces the chances
of false positives from looking at itself too much, and also speeds
up the test a little.

Change-Id: If361aa98bef789b1f841741a7c83bcb2ac9edf05
2021-02-13 03:00:57 +00:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
jenkins-bot
085f7d5c22 Merge "Make TypeDefTestCase::getInstance() abstract." 2021-02-09 08:46:29 +00: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
jenkins-bot
1e68c102c7 Merge "More improvements for ApiWatchTest" 2021-02-08 17:17:23 +00:00
Ammarpad
fa0c3fa26c More improvements for ApiWatchTest
* Remove notes about being broken, the tests are in better shape now.
* Don't return $data from testGetRollbackToken(), it's not used in
testWatchRollback() as it's being overshadowed.
* Just pass the minimum required values to the dependent test.

Bug: T273603
Change-Id: I7e23fe4769b45cb9ec4e7f3ac8980ccf63e5d492
2021-02-08 10:05:08 +01:00
Cindy Cicalese
f8e1fcacbb Use UserEditTracker in ApiQueryUserInfo::getLatestContributionTime()
Bug: T273788
Change-Id: I5d53fbe84dc3904f042a0f183d8d92b4f9695036
2021-02-07 15:52:58 -05:00
jenkins-bot
e4f6689170 Merge "Add test to ApiQueryUserInfo for latestcontrib timestamp" 2021-02-07 16:17:32 +00:00
Reedy
729f20afc8 Tests: Mark more closures as static
Bug: T274036
Change-Id: I911d3041cebe417d162934223b46ea295c6d20e3
2021-02-07 13:26:56 +01:00
Cindy Cicalese
089e014e9f Add test to ApiQueryUserInfo for latestcontrib timestamp
Bug: T273788
Change-Id: I188402feee3a6ad6cb3198aedbabb5b3ca4d7fb8
2021-02-07 01:42:15 -05:00
Umherirrender
a4340532e9 Set tablesUsed to watchlist for some api tests
This avoids leaking watchlist data between the test runs

Change-Id: I5b04849af0b001c5c114fde74c39e46423fe2280
2021-02-06 19:53:58 +01:00
Ammarpad
252fd6ff97 Make TypeDefTestCase::getInstance() abstract.
Required to be overriden by every subclass via direct override
or the indirect static property, which is used only for this
purpose.

The benefit of that is this automatically allow us to remove the
custom Logic exception/property null handling. It also obsoletes
the property itself, which is already a form of redundancy.

Additionaly it removes duplication in classes that are providing
the property and duplicating the base class method code, like
StringDefTest.php

It's better if every child class provide the needed instance via
consistent way and that which is not redundant with another.

Change-Id: Ibe10c2c01b381190cc92e7ee2e1e0888c16e5bf4
2021-02-06 12:31:00 +01:00
jenkins-bot
c5caf7b546 Merge "Make ApiErrorFormatterTest more robust." 2021-02-05 22:16:37 +00:00
daniel
7f4b3e9fcb Make ApiErrorFormatterTest more robust.
We intend to apply de-duplication of errors to StatusValue.
ApiErrorFormatterTest would break because it uses the same message
codes for errors and warnings, expecting them to both be retained.
This is fixed by using different error codes for testing errors and
warnings.

Change-Id: Iaa4811884efa2be076bcfa33911c3dc14c3af5d1
2021-02-05 16:21:19 -05:00
jenkins-bot
cdb17d6ad6 Merge "Fix and re-enable broken ApiWatch test" 2021-02-05 20:47:32 +00:00
jenkins-bot
d749cbdf38 Merge "Use __CLASS__/::class to define callback for array_map/_filter/usort" 2021-02-05 03:14:42 +00:00
jenkins-bot
9fa1d86728 Merge "Improve some class properties documentation in tests" 2021-02-05 02:52:22 +00:00
jenkins-bot
55b74a7c94 Merge "Re-enable the lone test in ApiPurgeTest" 2021-02-02 23:30:49 +00:00
Ammarpad
5e6cccc3a4 Re-enable the lone test in ApiPurgeTest
This was disabled 10 years ago because Jenkins was not happy.
We should reenable it and see whether it's happy now, otherwise
the test should be deleted.

Use MediaWikiTestCase::getExistingTestPage() to make sure the page
exists which is another reason given for skipping the test even if
not broken in whole.

Change the test name to more correct 'testPurgePage'

See https://phabricator.wikimedia.org/rMW7a0353b01080

Bug: T273603
Change-Id: Ief2017751256c683c8e4e4df375d5a82bcb4849c
2021-02-02 22:24:59 +00:00
Ammarpad
63951ea911 Fix and re-enable broken ApiWatch test
This was disabled since 2011.

Bug: T273603
Change-Id: Ia28db2e1cf5cb2353ad1782be9634b654a009c14
2021-02-02 22:22:03 +01:00
jenkins-bot
3fbe3c626c Merge "ApiLoginTest: Remove testGotCookie that's been broken for 10 years" 2021-02-02 19:32:43 +00:00
Ammarpad
3953ffa1c1 ApiLoginTest: Remove testGotCookie that's been broken for 10 years
For a decade (since https://phabricator.wikimedia.org/rMWa11cf96d0688)
this test has not been executed. It's safe to assume that it's useless
now and this code is better deleted.

It still fails if re-enabled and it seems to me the reason for its
brokenness is still there, so it's simply not fixable.

Bug: T273603
Change-Id: I6887cb88ae0a2d6665b018246215855498a7ff42
2021-02-02 19:07:00 +00:00
Ammarpad
a944bc6b6b Improve ApiWatchTest
I am splittig this off from a patch that will fix and re-enable
testWatchRollback test which has been broken for over 10 years.

* Remove fake time resetting, this is always done by the base
test class.
* Stop skipping a test because the test page does not exist,
since we can control its existence.
* Use ApiTestCase::setExpectedApiException()
* Make testGetRollbackToken() to return more data to be used by
testWatchRollback()
* Fix some style issues

Change-Id: I7d7d403130e23e5843ea3c3abdc019c9df239f3e
2021-02-02 18:16:18 +01:00
Umherirrender
205f141bb8 Improve some class properties documentation in tests
Change-Id: Id9c9e56865cf9a6bb112be37a5674ec753604fb1
2021-02-02 16:48:15 +00:00
Umherirrender
f20c0ac8bb Remove incomplete @param from test function
the @dataProvider should be a enough here

Change-Id: I36549dcac027a68244de042d48d90d4070771be8
2021-02-01 20:19:22 +01:00
jenkins-bot
eb4b304ed8 Merge "Add missing @param and @return to documentation in tests" 2021-01-30 15:22:33 +00:00
Lucas Werkmeister
1bf4af094f Allow replacing ApiResult value with same value
There’s no need for setValue() to raise an error if the old and new
value are identical.

Bug: T160504
Bug: T202725
Bug: T271105
Change-Id: Icfa6c181666b2293494c67875777d3de8816587a
2021-01-26 15:51:07 +01:00
Umherirrender
47cc4da6d7 Remove unneeded @return documentation
Change-Id: If79d2126cc1b6a6e9876a972c9560d045de42ff6
2021-01-25 19:44:27 +01:00
Umherirrender
7691dbeca9 Add missing @param and @return to documentation in tests
Change-Id: Ic663e81cca0bf007804a70772250914a85f1fef4
2021-01-22 19:57:25 +01:00
Umherirrender
e4d1a2c8bd Use __CLASS__/::class to define callback for array_map/_filter/usort
Change-Id: I3519dd5a1ce1ea688de602190cd74755c400c717
2021-01-22 16:39:29 +00:00
jenkins-bot
09288e646d Merge "Misc cleanup to api integration tests" 2021-01-21 07:32:08 +00:00
DannyS712
e715dbd4a4 Misc cleanup to api integration tests
Each file's changes are separate and can be reviewed independently

Change-Id: Ic0c24fa3f1616bb3428416a29d245a7e0bbb21b6
2021-01-21 06:32:58 +00:00