Commit graph

947 commits

Author SHA1 Message Date
daniel
246c543737 ApiPageSet: replace Title in method signatures
Bug: T278459
Change-Id: Ie817fd476d6236791431b5ba5ce557800ef5222d
2021-05-12 23:17:59 +02:00
DannyS712
95ab3b9f9c Tests: stop calling MediaWikiIntegrationTestCase::editPage() statically
Its not a static method and should not be called as such

Change-Id: I9dfdeed38cba90293b1f8bf1de775b343d2de7a9
2021-05-12 07:37:24 +00:00
STran
a3e8ca737b Return the action name instead of action id in API response
When block restrictions are queried from the API, return the name
of the action blocked

Bug: T280566
Change-Id: I2e639864cfcdd3854fd67173b138fe8eb6f877cb
2021-05-11 07:48:52 -07:00
DannyS712
31676abea5 Add DummyServicesTrait::getDummyInterwikiLookup
Replacing the mock InterwikiLookup used in
MediaWikiTitleCodecTest revealed that that test was,
because of the mock not behaving correctly, testing the
wrong thing - interwiki prefixes are *not* case sensitive,
and are always converted to lowercase in the actual
ClassicInterwikiLookup. Fixed those expectations.

Change-Id: I242431e88860b7700a9f93f77a0fe195fd748800
2021-05-05 10:57:59 -07:00
jenkins-bot
5127fe1b43 Merge "Add MediaWikiIntegrationTestCase::runJobs() and use it" 2021-05-05 03:15:17 +00:00
Tim Starling
0e05879d7e Add MediaWikiIntegrationTestCase::runJobs() and use it
JobRunner catches all exceptions and hides them in the status array,
meaning that it is not obvious when a job fails during a test case.
So, introduce MediaWikiIntegrationTestCase::runJobs(), which runs jobs
and asserts various things about the returned status array.

Depends-On: I4f4790c5d16a0767790eeff202e0be8fcdaeda93
Depends-On: I118f9e3f8950fd82d7b02baed6705b29fd6ab7d5
Change-Id: I63603aa158f77df4b40add096cb248f3b24979f4
2021-05-05 02:51:30 +00:00
Thalia
6cb1016594 Allow partial action blocks to be made via ApiBlock
Bug: T280522
Change-Id: I114e3c76cfb6dd2f79b5217aee4b3da34df00850
2021-05-04 17:48:21 +01:00
Thalia
c8736c949c ApiBlockTest: Separate out page and namespace restrictions tests
Make the assertions per test more focussed and stop relying on
restrictions being in a certain order.

Change-Id: I75e8d8d44eb43b894f72503ead55bd95dc4b72bf
2021-05-04 17:48:12 +01:00
DannyS712
b876af50cc Fix order of parameters in assertions
Should be expected, and then actual

Switched some assertEquals to assertSame to fix failing
phpcs sniffs

Change-Id: I7257c5afacd22fed78a58f3cc918b721ac11a46d
2021-05-03 15:50:53 +00:00
DannyS712
6ea78705e2 ApiRevisionDeleteTest: remove use of Revision objects
Since this isn't a test for the Revision code, it should have
been updated to use RevisionRecord a while ago rather
than just suppressing the deprecation, oops.

Bug: T247143
Change-Id: I2daf5ecac7fbc4fea78e98688023090febb90282
2021-05-02 03:31:18 +00:00
DannyS712
c0dd682544 Start removing places using Revision objects
- EditPage::$mBaseRevision
- EditPage::getBaseRevision()
- Title::getFirstRevision()
- LinksUpdate::setRevision()
- LinksUpdate::getRevision()
- Article::$mRevision
- Article::getRevisionFetched()
- WikiPage::getOldestRevision()
- WikiPage::getRevision()
- ContribsPager::tryToCreateValidRevision()

To make things easier, instead of rewritting
the Revision tests that were using WikiPage::getRevision,
just delete them, its not worth the effort to rewrite
them since the class is going away. For the WikiPage
tests, replace uses of getRevision with getRevisionRecord,
manually converting to a Revision object where needed

Bug: T247143
Change-Id: I52bc1f49649f8bd25797e3f7a090bec9c63ac2d1
2021-04-30 12:33:15 -07: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
Cindy Cicalese
f1728cd6e9 Replace use of User::isWatched with WatchlistManager::isWatched
Change-Id: I67713c74f8beae9afd5210f7dff0f180c2cf691b
2021-04-28 18:59:41 -04:00
jenkins-bot
a8196f5904 Merge "Introduce infrastructure for partial blocks for actions" 2021-04-27 23:57:33 +00:00
Thalia
c67f181dd4 Introduce infrastructure for partial blocks for actions
This adds a new type of block restriction for actions, which extends
AbstractRestriction. Like page and namespace restrictions, action
restrictions are stored in the ipblocks_restrictions table.

Blockable actions are defined in a BlockActionInfo service, with a
method for getting all the blockable actions, getAllBlockActions.

Action blocks are checked for in PermissionManager::checkUserBlock
using DatabaseBlock::appliesToRight. To make this work, this patch
also removes the 'edit' case from AbstractBlock::appliesToRight,
which always returned true. This was incorrect, as blocks do not
always apply to edit, so cases that called appliesToRight('edit')
were fixed before this commit. appliesToRight('edit') now returns
null (i.e. unsure), which is correct because it is not possible to
determine whether a block applies to editing a particular page
without knowing what that page is, and appliesToRight doesn't know
that page.

There are some flags on sitewide blocks that predate partial blocks,
which block particular actions: 'createaccount' and 'sendemail'.
These are still handled in AbstractBlock::appliesToRight, and are
still checked for separately in the peripheral components.

The feature flag $wgEnablePartialActionBlocks must set to true to
enable partial action blocks.

Bug: T279556
Bug: T6995
Change-Id: I17962bb7c4247a12c722e7bc6bcaf8c36efd8600
2021-04-27 21:53:13 +01:00
jenkins-bot
e2abc63ac6 Merge "RecentChange: replace Title in method signatures" 2021-04-26 22:24:57 +00:00
jenkins-bot
bc46ba2de9 Merge "Hard deprecate User ::isIP, ::getOptions" 2021-04-26 17:06:00 +00:00
vladshapik
9cc797695b Hard deprecate User ::isIP, ::getOptions
Bug: T275602
Change-Id: Id4be13751ca0a900e51214c1855a4624077a5a62
2021-04-26 16:10:24 +00:00
daniel
c7eca76241 RecentChange: replace Title in method signatures
Bug: T278459
Change-Id: I144ea130f29ec437302649d86494034af044c524
2021-04-26 17:48:02 +02:00
Petr Pchelko
bf6d3c5cf3 Regression tests for ApiRollback and RollbackAction
Bug: T280655
Change-Id: I933b80bbe9bd33ffda68f9a5ab84424cb531abff
2021-04-26 07:58:44 -07:00
jenkins-bot
89b00fcfbe Merge "Remove unnecessary ->equalTo() from tests" 2021-04-23 14:43:04 +00:00
Thiemo Kreuz
c1ee8250e9 Remove unnecessary ->equalTo() from tests
This is the default anyway when using ->with(). The test code
becomes so much more readable without this, I would like to
argue. Let it just say "with these values".

Because of the way I split my changes into multiple patches
there are a few other changes in this patch I could not split,
e.g. removing unnecessary ->any(). This is the default anyway
and doesn't make the test more specific.

Change-Id: I34990799fa9258ba8dc64c7e78ec43f7903b7681
2021-04-23 12:02:42 +02:00
Thiemo Kreuz
b95a07380a Remove meaningless ->expects( $this->any() ) from all tests
It is not entirely meaningless. It might be an indicator that
the number of calls to a method is intentionally unlimited.
This is similar to e.g. an @inheritDoc PHPDoc comment that
marks a method as being "intentionally undocumented".

However, what's the meaning of being "intentionally
unconstrained"? Let's just not have any constraint then.

I feel all these ->expects( $this->any() ) bloat the test
code so much that it's never worth it.

Change-Id: I9925e7706bd03e1666f6eb0b284cb42b0dd3be23
2021-04-23 11:58:58 +02:00
Thiemo Kreuz
40764d277c Replace PHPUnit ->returnValue() with ->willReturn() shortcut
It's the same and makes the test code much more readable, I
would like to argue.

Because of the was I split all the changes I made into smaller
patches this patch contains some other changes in the same
lines where I could not split them off. E.g. removal of
->any(), which is the default anyway and doesn't do anything.

Change-Id: Ib297b989d4aec33b31a4e33fe9d5032865b39be0
2021-04-22 10:37:45 +02:00
Cindy Cicalese
b242d49a62 Use WatchlistManager in API classes
Change-Id: I7b2016162e86b455c0102742751981c44d7e829c
2021-04-21 04:41:06 +00:00
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