Commit graph

105 commits

Author SHA1 Message Date
Fomafix
c532f8954d use setGroupPermissions instead of mergeMwGlobalArrayValue
Change-Id: Ibda0fc63681e0bc0acbb290474b2d2bea87cfb6d
2024-08-07 21:50:00 +00:00
Reedy
b52a8addf5 Drop writeapi userright
Bug: T294397
Depends-On: Ib34228a18917e404517d45e539bd786419d9c401
Change-Id: Ifad2edc782b36d21c8c67fecde7f011dce02c11b
2024-07-31 11:10:50 +00:00
Ebrahim Byagowi
a717db8e60 Add namespace and deprecation alias to FormatJson
This patch introduces a namespace declaration for the
MediaWiki\Json to FormatJson and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I5e1311e4eb7a878a7db319b725ae262f40671c32
2024-05-16 16:28:01 +03:30
Umherirrender
fe5a3ebd1f tests: Use IDatabase for mocking instead of DBConnRef
DBConnRef is internal, use of IDatabase interface is more common

Change-Id: Id7649d0723a936cebc7e5a40bf826e38220acee5
2024-05-02 22:11:12 +00:00
Amir Sarabadani
8e183495e1 Stop using LoadBalancer::getConnectionRef() so it can be hard-deprecated
Bug: T326274
Change-Id: I90493d7cd4c21fdc022bcc19765fc04d986a9c8f
2024-04-30 13:31:08 +01:00
Dreamy Jazz
d6ac3dac74 Catch exceptions from ::isWriteMode in ApiMain::sendCacheHeaders
Why:
* Modules that extend ApiQueryBase are loaded using the ApiQuery
  module. This defines an override to the ApiBase::isWriteMode
  method that loads the modules.
* Using the mModule when $isError is true could lead to the
  exception that was thrown in ::executeAction being thrown again.
* Therefore, ApiMain::sendCacheHeaders should only call the
  ApiBase::isWriteMode method if the request did not fail
  with an error that caused $isError to be true.
* Without this fix, ApiUsageExceptions appear in logstash as
  exceptions, as described in T363133.

What:
* Only interact with $this->mModule if the $isError argument
  is false. If $isError is true, assume that ::isWriteMode
  would return true. Assuming this will also avoid error
  responses being marked as fresh for any amount of time, as
  the error may be temporary.
* Add a test that verifies that the method does not throw if
  ApiBase::isWriteMode throws an ApiUsageException.

Bug: T363133
Change-Id: I41d869c257878b8a94d6c40332e2028405de8729
2024-04-23 21:15:23 +01:00
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
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
Umherirrender
c99e804f0b tests: Remove unused variable after ConvertibleTimestamp::setFakeTime
ConvertibleTimestamp::setFakeTime does not return a ScopedCallback,
which would need a local variable, it returns the old value.
The reset is part of MediaWikiTestCaseTrait.

Change-Id: Ic479ec810f3f75cbdd393f2d91afb7a311d798a0
2023-12-27 16:36:14 +01:00
Umherirrender
87850b30b8 tests: Use ::class for class name resolution
Change-Id: I120bac20e764cc32aeadc7e05c31d2bc9d1a4822
2023-12-06 20:51:14 +01:00
Amir Sarabadani
f5abfb8d58 Bump codesniffer to 42.0.0
Most noisily, this enables MediaWiki.Arrays.OneSpaceInlineArray.

Change-Id: I8ab11399c67ce7e3ab1b6249b591452774393428
2023-09-27 15:06:32 -04:00
James D. Forrester
c1599c91b3 Namespace Config-related classes under \MediaWiki\Config
Bug: T166010
Change-Id: I4066885a7ea071d22497abcdb3f95e73e154d08c
2023-09-21 05:41:58 +00:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
Amir Sarabadani
5bd33d46ef Reorg: Move WebRequest to includes\Request
This has been approved as part of RFC T166010

Bug: T321882
Change-Id: I6bbdbbe6ea48cc1f50bc568bb8780fc7c5361a6f
2023-09-11 21:44:34 +01:00
James D. Forrester
447400b423 rdbms: Drop old class aliases
Bug: T344536
Depends-On: I565541d781caaf564ae0c1877f5cb086e3650f22
Depends-On: Ia5fdf3242f9510e4f21670f3746d9364ae2935c6
Depends-On: I6f4b158bdc3ef20a1660e66accca0ffc17104f49
Change-Id: Ia87f1be7e0e68eb7cf792cb1f5ae64ecdfa2c015
2023-08-24 15:18:13 -04: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
580439e604 tests: Use MainConfigNames consts to refer config names
PasswordSalt was dropped in 2e909bcb

Change-Id: I58d2b8d4e2a235afdc8054eafdea4e85b61f03c1
2023-06-19 20:21:08 +00:00
Daimona Eaytoy
0d29958cc1 Replace more usages of deprecated MWException
Bug: T328220
Change-Id: Ib619ead0f397188d828e6e5dfc80ed1fa7175c7d
2023-06-08 21:37:07 +00: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
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
Amir Sarabadani
bc1af1a53a Reorg: Move WebResponse and FauxResponse to Request/
Bug: T321882
Change-Id: Iae8b9e0170c67c1adf861a6d0da45178a7d3cca7
2023-03-01 18:18:11 +01:00
Amir Sarabadani
523ab7cff8 Reorg: Move RawMessage to under language/
To follow Message. This is approved as part of RFC T166010.

Also namespace it but doing it properly with PSR-4 would require
namespacing every class under language/ and that will take some time.

Bug: T321882
Change-Id: I195cf4c67bd51410556c2dd1e33cc9c1033d5d18
2022-12-16 11:30:19 +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
Amir Sarabadani
0fff5089ba Reorg: Move StubObject classes in includes to its own directory
Bug: T166010
Change-Id: Idcf0e9dc6e0841e4f132207bce0f96774dad898c
2022-10-25 16:04:48 -04:00
Derick Alangi
a3a2ed268a tests: Use overrideConfig(Value|Values) where needed
This patch covers: tests/phpunit/includes/actions/ and
tests/phpunit/includes/api/.

Change-Id: I60d8fb7b8a63b423606db935fa0d24cf859b2512
2022-07-12 22:24:50 +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
Timo Tijhof
8d406bbcd6 phpcs: Disable Generic.Files.LineLength for test files
There is a common and reasonable need for longer lines in tests.
The nudge for shorter lines doesn't seem valuable here. The natural
breaks will likely still fall in 80-100 given the enforced practice
for non-test code, e.g. whether through habit, or 80-100 column markers
in text editors, or the finite width of diff and code review
interfaces.

Change-Id: I879479e13551789a67624ce66f0946d2f185e6ee
2022-02-18 18:32:05 +00:00
jenkins-bot
99d0848db7 Merge "Add tests for ApiMain::sendCacheHeaders" 2022-01-10 01:54:17 +00:00
Reedy
8c39aab84b Remove or replace usages of "sanity"
Bug: T254646
Change-Id: Ib192dc5704a14d02c7c374d0ab29bac55c5df24a
2021-11-21 19:35:49 +00:00
Reedy
6e29611642 Remove or replace usages of "sanity"
Still some more to go...

Bug: T254646
Change-Id: Ia117f01e443c35b4765f3275cab4f2707e1be96f
2021-11-21 16:42:31 +00:00
Daimona Eaytoy
2f6bfb126d Add tests for ApiMain::sendCacheHeaders
This is just a start, and only tests common situations. It's also
best-effort, since this code path is hard to follow (partly due to the
OutputPage usage).

Change-Id: I59e228982c5a5aff387698c0cce2b0ec5da4c566
2021-10-26 17:25:31 +02:00
jenkins-bot
5af89e32c7 Merge "Emit deprecation warnings reading from $wgUser" 2021-09-16 15:27:44 +00:00
DannyS712
a2b20b63d7 Emit deprecation warnings reading from $wgUser
With this patch deprecation warnings will be emitted
if $wgUser is accessed or written into. The only pattern
of usage still allowed is

$oldUser = $wgUser;
$wgUser = $newUser;
// Do something
$wgUser = $oldUser;

Once there is no deprecation warnings, we know that nothing
legitimately depends on $wgUser being set, so we can safely
remove the code that's still allowed as well.

Bug: T267861
Change-Id: Ia1c42b3a32acd0e2bb9b0e93f1dc3c82640dcb22
2021-09-15 20:17:04 -07:00
jenkins-bot
d018c4f6ed Merge "rdbms: Add more return typehints" 2021-09-14 20:51:25 +00:00
Daimona Eaytoy
613a874635 rdbms: Add more return typehints
See full rationale at I59068cfed10aabf6c6002f9e9312a6ef6e7e9441.
Using IDatabase for now instead of DBConnRef for better BC.

Change-Id: Ie75aaf46ba91779e8706b10efeefa9580857f489
2021-09-07 08:23:36 +00:00
Umherirrender
2e4ee47c3d Cleanup mixed space/tab line indent
Change-Id: I833052a656b1ce419c0929f6f0514f2a33c2c4cc
2021-09-04 00:52:31 +02: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
Reedy
fb4cd73d83 api: Update mailman links
Change-Id: Ib48f04d4debb3e66ef7e67730d6c7ddbaaf85d3b
2021-07-13 20:49:20 +00:00
Petr Pchelko
edb3a9a692 Allow passing mock Authority in API integration tests
This is a demo, a lot of tests could be rewritten as a followup
to pass proper Authority when executing tests instead of writing
globals. Much cleaner imho.

An improvement idea is to allow overriding 'default permissions'
when creating a mock Authority.

Change-Id: I38570024e0d5a67a8e1c52f7456c458090ec2b6e
2021-06-07 11:50:42 -07: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
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
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
Umherirrender
7691dbeca9 Add missing @param and @return to documentation in tests
Change-Id: Ic663e81cca0bf007804a70772250914a85f1fef4
2021-01-22 19:57:25 +01:00
Thiemo Kreuz
b655f382db Remove broken/outdated @param/@throws tags from @dataProviders
My personal best practice is to not document @params when there
is a @dataProvider. I mean, these test…() functions are not
meant to be called from anywhere. They do not really need
documentation. @param tags don't do much but duplicate what the
@dataProvider does. This is error-prone, as demonstrated by the
examples in this patch.

This patch also removes @throws tags from tests. A test…() can
never throw an exception. Otherwise the test would fail.

Most of these are found by the not yet released I10559d8.

Change-Id: I3782bca43f875687cd2be972144a7ab6b298454e
2021-01-21 03:42:42 +00:00
Umherirrender
0347fd0631 Improve some function documentation in tests
Also fix some whitespaces

Change-Id: Ibed50a4f07442d3f299cf545c16f5dbb5f27a411
2021-01-14 22:13:55 +01:00
Tim Starling
8212527dfe Fix hang of ApiMainTest
If I try to run ApiMainTest with GlobalPreferences enabled, it takes
forever (or at least some number of minutes) to run. This is because
when @depends is used to transfer data from one test to another via
the return value, PHPUnit runs Enumerator::enumerate() on the data. When
it contains a reference to the active TestCase, PHPUnit ends up
iterating through its internal data structures, which takes a long time.

My conclusion is that @depends with a return value should be considered
harmful. Stop doing it in ApiMainTest. Stop recommending it in
SampleTest.

Change-Id: I63e94f2886a4ee4b3fd0ea6b19cd2fb67ba912de
2020-12-16 15:39:19 +11:00
Bartosz Dziewoński
245aa6e34c Fix error message mentioning the removed $wgEnableWriteAPI config
Change-Id: Idee35e7d37ea17f0a6bdbdc70b45822ec7c89b71
2020-12-15 23:38:03 +01:00