Commit graph

95 commits

Author SHA1 Message Date
Func
4d1da6f7f8 phpunit: Update @covers annotations for namespaced classes
We renamed many classes to be namespaced, but the `@covers` and
`@coversDefaultClass` annotations weren't updated properly.

PHPUnit didn't support short cover annotations with `use` statements,
these didn't trigger any errors yet, because they are class alias.

This patch is populated by a modified version of PhpunitAnnotationsSniff.

Change-Id: I6c602290a30099239b17d2dc0d67b1488b4eaeeb
2023-05-27 17:43:12 +08:00
libraryupgrader
7375f3a5fe build: Updating mediawiki/mediawiki-codesniffer to 41.0.0
The following sniffs are failing and were disabled:
* MediaWiki.Usage.ForbiddenFunctions.eval

Change-Id: I6fd0a9296c88a77c3abec6e5e8d568bb469c2d6e
2023-03-11 19:04:09 +00: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
Reedy
0cb2c3c106 Fix casing of class and function name usages
Bug: T253628
Change-Id: I5c64f436d3cf757390b751ce3e34bfc7872bc176
2022-12-04 19:09:30 +00:00
Bartosz Dziewoński
f68a3af333 Message: Improve parameter type errors
…and avoid the use of MWException.

Change-Id: Id07e301c3f20afa135e5469ee234a27354485652
2022-12-01 20:31:57 +00:00
Reedy
e673eb3815 Partial Revert "Remove pre PHP 7.4 serialize()/unserialize()"
This reverts commit 27ee63f8c9.

Reason for revert: Serialized Messages are stored in the database

Bug: T323236
Change-Id: Ia8089201eedf3c0585bb7e970b3776a7e0882019
2022-11-21 02:51:31 +00:00
Reedy
27ee63f8c9 Remove pre PHP 7.4 serialize()/unserialize()
Depends-On: I3b893152ed278a72b5e74ccf91a3381f319bfcd9
Change-Id: I9f69a9316eaec23103262ec2ffd5b85baaf16f3f
2022-11-10 19:25:01 +00:00
Derick Alangi
9899846d10
tests: Use overrideConfigValue(s) where necessary
The files in `tests/phpunit/includes/` directory are now all
covered. Will do sub-directories of `/includes/` next.

Change-Id: I8d5655ce267b6d32cf3c7ee40dc5d2992631b5a6
2022-07-16 23:45:52 +01:00
Bartosz Dziewoński
ba96351f46 Only apply transformations for &uselang=qqx when actually using it
Depends-On: I4f3b01eccf571475f1248db838a8aa6cba18b93e
Depends-On: I0a0681b332abb623fc6871ab78da9e64a79fad84
Bug: T300069
Bug: T302469
Change-Id: I45f58034117e9041fe5403dbfcf83ba25f20518d
2022-03-08 01:50:44 +00:00
Bartosz Dziewoński
04b9dd6b2f Re-apply "Show message fallback keys when using &uselang=qqx"
This affects messages created using wfMessageFallback() and related
functions, in particular many messages used for navigation tabs in
skins.

Previous attempt in 11d7d97768,
reverted in c83b530f95 due to T302469.

This attempt doesn't introduce any new placeholders to avoid that
issue.

Bug: T300069
Change-Id: Ib0e282b3864caf345e42dd7af4a529f43ae7ba67
2022-03-08 00:56:12 +00:00
Elliott Eggleston
c83b530f95 Revert "Show message fallback keys when using &uselang=qqx"
This reverts commit 11d7d97768.

Breaking fundraising banners with regexes in them.

Bug: T302469
Change-Id: I0146a6a2907ca72792375e97a5b5392c6465614f
2022-02-23 21:21:45 -05:00
Bartosz Dziewoński
11d7d97768 Show message fallback keys when using &uselang=qqx
This affects messages created using wfMessageFallback() and related
functions, in particular many messages used for navigation tabs in
skins.

Bug: T300069
Change-Id: Ia8ba35419285cfa77197810ae9df99e522a0f4ba
2022-02-17 19:59:40 +01:00
Alexander Vorwerk
decbaf4f38 phpunit: use ->getServiceContainer() in integration tests
Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
2022-01-27 22:04:16 +01:00
Reedy
8c39aab84b Remove or replace usages of "sanity"
Bug: T254646
Change-Id: Ib192dc5704a14d02c7c374d0ab29bac55c5df24a
2021-11-21 19:35:49 +00:00
TChin
349819dc5a Add Message/MessageValue user group member parameter type
* Added ParamType::OBJECT, which allows Stringable objects to be passed into MessageValue

Bug: T278482
Change-Id: Ib4990f87d4ad70b7525d7aa05c8b97e90c121674
2021-11-16 11:24:35 -05:00
TChin
fb4e7a803a Add message parameter type for User Groups
Bug: T278482
Change-Id: I45da5f73f8920b79b57c02776a05d0268d3480f2
2021-10-14 15:02:13 -04:00
Gergő Tisza
86fcccf0a8 Message: Remove deprecated format property
Remove Message::$format and the $format parameter of
Message::toString(), soft-deprecated in 1.26 and hard-deprecated
in 1.36. Also make the signature of toString() stricter.

Bug: T146416
Change-Id: I19aa3e482968dea5164afb93b04a55f27c644ce6
2021-09-03 09:21:12 -07: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
Petr Pchelko
92564edc7c Use Message::page instead of Message::title
Also modified new APIs added to ApiErrorFormatter to
use PageReference instead of Title.

Change-Id: I093c89f8e1e6d383603f887358be6ece70f23a02
2021-06-09 13:18:22 +00:00
Petr Pchelko
bdecf516b9 Replace Title in Message/MessageCache
Change-Id: Ib0e36d767788edcdd8fa9ebc5de6bbde4cf50f12
2021-06-09 06:16:56 -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
jenkins-bot
b57ace7aee Merge "Replace PHPUnit ->returnValue() with ->willReturn() shortcut" 2021-04-22 15:47:14 +00: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
Timo Tijhof
73e718e373 Message: Deprecate toString() with an implicit format
This functionality exists to enable the anti-pattern of calling a
format method, without using its return value, and then subsequently
calling toString() to parse the same message, the same way, a second
time with the format you just called.

For example:

```
$msg = new Message('laggedreplicamode');

echo $msg->plain();
// <strong>Warning:</strong> Page may not contain recent
echo $msg->toString();
// <strong>Warning:</strong> Page may not contain recent

echo $msg->escaped();
// &lt;strong&gt;Warning:&lt;/strong&gt; Page may not contain recent
echo $msg->toString();
// &lt;strong&gt;Warning:&lt;/strong&gt; Page may not contain recent
```

Deprecate this rare anti-pattern in favour of using the return value
from the formatting methods such as $msg->plain() and $msg->escaped(),
or for compat we can also support $msg->toString('plain') etc.

This commit also fixes an unintentional lie in the assertion message
of one of the unit tests, which was claiming that toString() is
unaffected by format calls, when in fact it is. (And is what we are
deprecating here).

This implicit formatting and the related $this->format field will
be removed in 1.37.

Bug: T146416
Depends-On: Ia257621fb421854bf13e2965b04009663711ba0a
Change-Id: Ibb22099ff8042406e441d6c7fab87537d3ac92aa
2021-04-22 00:18:59 +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
c71781f54c Add Message/MessageValue datetime parameter types
This is used quite a lot in the codebase and it's
a reason for a lot of usages of $wgLang. Time and date
seems generic enough to put into Message library -
we already have references to Wikimedia\Timestamp
library there.

Bug: T278482
Change-Id: If7cb5f5dcfa736b6530f731af9dc3af168812054
2021-03-30 21:05:32 -06:00
Umherirrender
4bdaf3af19 tests: Use ::class on exception names
Change-Id: Iadc2eabb7d132a21cffccf5468b92328a64acb4a
2021-01-03 20:47:49 +01:00
Thiemo Kreuz
6aa6d10e86 Replace all call_user_func(_array) in all tests
There is native support for all of this now in PHP, thanks to changes
and additions that have been made in later versions. There should be no
need any more to ever use call_user_func() or call_user_func_array().

Reviewing this should be fairly easy: Because this patch touches
exclusivly tests, but no production code, there is no such thing as
"insufficent test coverage". As long as CI goes green, this should be
fine.

Change-Id: Ib9690103687734bb5a85d3dab0e5642a07087bbc
2020-06-06 18:41:20 +02:00
Max Semenik
48a323f702 tests: Add explicit return type void to setUp() and tearDown()
Bug: T192167
Depends-On: I581e54278ac5da3f4e399e33f2c7ad468bae6b43
Change-Id: I3a21fb55db76bac51afdd399cf40ed0760e4f343
2019-10-30 14:31:22 -07:00
jenkins-bot
17b931caf6 Merge "Remove Language::factory and getParentLanguage use" 2019-10-29 09:25:29 +00:00
Aryeh Gregor
0de9c47b50 Remove Language::factory and getParentLanguage use
Change-Id: I11f8801ef47ec1a1f63d840116e69667e6f3ae3c
2019-10-27 12:34:28 +02:00
Brad Jorsch
74f2902ed1 Try fixing flaky test
This test has been said to be flaky, and I suppose it could be if
it somehow regularly manages to tick a second in between the two calls
to wfTimestampNow(). So let's make just one call and reuse the value to
see if that fixes it.

Bug: T232266
Change-Id: I8fbdfa2f906839423cc238cd3741b94435a84505
2019-10-23 14:51:53 -04:00
James D. Forrester
83d76f4cb5 phpcs: Enable MediaWiki.Commenting.PhpunitAnnotations.ForbiddenExpectedException* and make pass
Change-Id: I63f97497714a32236268be6965c5e181dade6c58
2019-10-14 12:48:48 -07:00
Daimona Eaytoy
8545ce131a Kill the remaining usages of PHPUnit4And6Compat methods
Bug: T192167
Change-Id: I1ea19e9b53683b7d32ff9836990ee73ab3e11104
2019-10-06 10:12:54 +00:00
Aryeh Gregor
7fb4a95563 Remove unneeded overrideMwServices/resetServices
Change-Id: If6cbdec05b8f310ef3a0b4649aaa16d9fb80a047
2019-08-29 14:26:18 +03:00
Aryeh Gregor
752e7dd707 Convert MessageCache to service
Depends-On: Ia70e6c75f6e8a533f20cd44ebb05e013678e9951
Depends-On: I546eda0377f3a50843144b1450d3fbe8e4e02a8a
Change-Id: I305539a8598535a73e5cd280b2becdafa740ef97
2019-08-18 12:11:36 +03:00
Aryeh Gregor
e6df285854 Remove all $wgParser use from core
Bug: T160811

Change-Id: I0556c04d33386d0339e02e2bf7a1ee74d97c2abd
2019-04-17 15:16:50 +03:00
Kunal Mehta
643225cbc7 Add some missing @covers tags
Change-Id: Idb9af9515702ee9748755d7799663713b2283647
2019-02-02 21:53:40 -08:00
Aryeh Gregor
bca6085920 Use ParserFactory in a bunch of places
I wasn't sure how to convert the rest of the occurrences in core (there
are a significant number).

Bug: T200881
Change-Id: I114bba946cd3ea8a293121e275588c3c4d174f94
2018-08-11 00:16:17 -06:00
Aryeh Gregor
63d7f2ad13 Automatically reset namespace caches when needed
This avoids error-prone code written separately in every test.  In
addition to no existing tests resetting the TitleFormatter (more
services probably need to be reset as well), they mostly reset only the
namespace cache on $wgContLang, which wouldn't help for any other
language.

The parser test runner still doesn't do this, but maybe it should.

Change-Id: I44b7a1aec48f14b0950907fa14bd0df80f674296
2018-08-01 16:30:08 +03:00
Kunal Mehta
79de8fd02f Use wikimedia/object-factory 1.0.0
Deprecate the unnamespaced version and move it to includes/compat.

Bug: T147167
Depends-On: I39c805bfb98b32f32f3d0dc1eee9e823afe1c21a
Change-Id: I3780c7adf51683f3f7adb35a88f9a25a0a2e2530
2018-02-04 12:52:44 -08:00
Umherirrender
45da581551 Use ::class to resolve class names in tests
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: Ie541a7baae10ab6f5c13f95ac2ff6598b8f8950c
2018-01-26 22:49:13 +01:00
addshore
e6e59bb425 Remove method level @group Database tags
MessageTest did not have the group at class level
either so that is added in this patch.

Change-Id: Idb6213282d6854044f374c9df51ea32d0a5523e1
2017-11-23 19:20:44 +00:00
Gergő Tisza
525bfbc8df Switch to librarized version of TestingAccessWrapper
Replaces \TestingAccessWrapper (defined in core) with
\Wikimedia\TestingAccessWrapper (defined in the composer package
wikimedia/testing-access-wrapper).

See https://gerrit.wikimedia.org/r/#/q/topic:librarize-testing-access-wrapper
for downstream patches.

The core version of the class is kept around for a while to avoid
circular dependency problems.

Bug: T163434
Change-Id: I52cc257e593da3d6c3b01a909e554a950225aec8
2017-04-20 14:15:57 +00:00
Brian Wolff
1c7889446d SECURITY: Disable <html> tag on system messages despite $wgRawHtml = true;
System messages may take parameters from untrusted sources. This
may include taking parameters from urls given by unauthenticated
users even if the wiki is a read-only wiki. Allowing <html> tags
in such a context seems like an accident waiting to happen.

Bug: T156184
Change-Id: I661f482986d319cf41da1d3e7b20a0f028a42e90
2017-03-28 21:51:44 +00:00
Bartosz Dziewoński
ecdef925bb Miscellaneous indentation tweaks
I was bored. What? Don't look at me that way.

I mostly targetted mixed tabs and spaces, but others were not spared.
Note that some of the whitespace changes are inside HTML output,
extended regexps or SQL snippets.

Change-Id: Ie206cc946459f6befcfc2d520e35ad3ea3c0f1e0
2017-02-27 19:23:54 +01:00
James D. Forrester
1e9c361960 tests: Replace implicit Bugzilla bug numbers with Phab ones
It's unreasonable to expect newbies to know that "bug 12345" means "Task T14345"
except where it doesn't, so let's just standardise on the real numbers.

Change-Id: I46261416f7603558dceb76ebe695a5cac274e417
2017-02-21 02:14:34 +00:00
Zhuyifei1999
c675393413 wfMessage: use Message::params() to handle all the message parameters
The old code was similar to Message::params(), but Message::params()
was unable to handle "special" parameters and received an overhaul
in 7f2663f, yet wfMessage remained broken. To avoid duplication,
wfMessage shall call Message::params() to correctly handle these
parameters.

CategoryMembershipChange::getChangeMessageText and its caller has
been updated so as not to take advantage of this bug.

Bug: T153747
Change-Id: I6667acf7e71c9db07fefc9fbb741c160e15823ff
2016-12-20 19:22:54 +00:00
Brad Jorsch
7f2663fb91 Message: Fix buggy parameter handling in Message::params()
Message::params() wants to take parameters either varargs-style or as a
single array. But it also detects "special" parameters like those
returned from Message::numParam() as an array of parameters instead of
as a single "special" parameter.

Bug: T152603
Change-Id: Idef2437470eee843a17ff23f4cefe8f3132988bd
2016-12-07 10:48:52 -05:00
Brad Jorsch
3041b5c038 Add Message::listParam()
This allows for passing a list of values that will be turned into a list
in the context of the language for which the Message is being processed.

For example, currently you'd have to do

 $msg = new Message( 'something', [ $language->commaList( $list ) ] );

which isn't going to give correct results if the message is later
changed to a different language with a different value for
'comma-separator'.

Now, you can do this instead

 $msg = new Message( 'something', [ Message::listParam( $list, 'comma' ) ] );

and it will be listified properly no matter what language is later used to
parse $msg.

Change-Id: I66868c61832260870449998fef14c842f17753ee
2016-11-30 15:54:17 +00:00