Commit graph

15 commits

Author SHA1 Message Date
Bartosz Dziewoński
279fd16bab tests: Avoid deprecated Status / StatusValue methods
Use more specific and less fragile assertions whenever possible;
most tests don't need to examine the internals of the status so
closely. Use StatusValue::getMessages() when necessary.

Change-Id: Ie4b3ebc03abb0e352e82394ced6ab9e733c83fb4
2024-06-15 10:14:37 +02:00
Umherirrender
6c41df61e9 tests: Use namespaced classes (1)
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: Iae45fa269363be8ee05c598ea6926514ce817762
2024-06-14 17:19:36 +00:00
Bartosz Dziewoński
d38c9a1ad1 StatusValue: Fix filtering out duplicate Message objects with context
Normally two Message objects can be compared with `==`, and they will
compare equal if they have the same key, parameters and internal state
such as the selected language.

However, if you call `setContext()` on a Message, it will never
compare equal to any other Message object, because a unique closure
is stored in the `userLangCallback` property.

Most implementations of MessageLocalizer::msg() use `setContext()`,
so filtering out duplicate Message objects in StatusValue usually
didn't work. Luckily most uses of StatusValue use string message keys.

Change-Id: Id22075bf73d37fd139c2ef7d80c69eeb462a7b68
2024-06-06 02:16:35 +02:00
Timo Tijhof
978cb38627 Status: Widen @covers tags in phpunit tests
Follows-up Ibc4ce11594cf36.

> We lose useful coverage and waste valuable time on keeping tags
> accurate through refactors (or worse, forget to do so).
>
> Tracking tiny per-method details wastes time in realizing (and
> fixing) when people inevitably don't keep them in sync, and time
> lost in finding uncovered code to write tests to realize it was
> already covered but "not yet claimed".
>
> Given all used methods are de-facto and liberally claimed, and
> that we keep the coverage limited to the subject class, this
> maintains the spirit and intent. PHPUnit offers a more precise
> tool when you need it (i.e. when testing legacy monster classes),
> but for well-written code, the class-wide tag suffices.

Ref https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:Widen

Change-Id: I6d66d5db2ca15441d3f26d54b0bd53913976c684
2024-05-28 22:14:33 +01:00
Bartosz Dziewoński
c66441d05c StatusValue: Document and deprecate broken ways to search/replace messages
StatusValue::replaceMessage() doesn't really work if given a
MessageSpecifier, and doesn't work at all if given a MessageValue.

StatusValue::hasMessage() and ::hasMessagesExcept() ignore the message
parameters when searching if given a MessageSpecifier or MessageValue.

Therefore, deprecate passing anything other than strings representing
message keys to these methods.

Change-Id: Icb4effc6c5319c12ba4ebeab447a0cef54f8e255
2024-05-03 17:04:27 +02:00
Bartosz Dziewoński
f818da9351 StatusValue: Add a getter for MessageSpecifier list
An array of MessageSpecifier objects is easier to deal with than the
"legacy error array" format, which is an array of whatever wfMessage()
accepts, which can be a bunch of different things.

Deprecate some existing getters.

Change-Id: Ibc4ce11594cf36ce7b2495d2636ee080d3443b04
2024-04-10 00:13:04 +02:00
Reedy
85396a9c99 tests: Fix @covers and @coversDefaultClass to have leading \
Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
2024-02-16 22:43:56 +00:00
thiemowmde
ab1e3a66e7 Make use of the [ ... ] operator instead of array_merge
The array spread operator is documented to behave identical to
array_merge. The syntax is just much shorter and easier to read in
situations like this, in my opinion.

Change-Id: I3b016e896e552af53d87d5e72436dc4e29070ce1
2024-01-31 15:47:44 +01:00
jenkins-bot
b2990e4a06 Merge "wfEscapeWikiText: protect string against wikitext tokens formed at edges" 2024-01-30 00:16:59 +00:00
Umherirrender
a3a9cf99cb tests: Use namespaced class names in @covers annotations
Assist from 8c9cb701e56226cac43fee2fa24b0d0e586f1733

Change-Id: I47897c499028d9e24c00ad0bc6ba7fd8002d9bc1
2024-01-27 01:11:07 +01:00
C. Scott Ananian
3fc635dcb2 wfEscapeWikiText: protect string against wikitext tokens formed at edges
The result of wfEscapeWikiText() did not consider inclusion of a string
within table context, and so `!!` and `!` at start of line were not
previously escaped.

Additionally, if you are inserting the result of wfEscapeWikiText()
into a wikitext string, the result can inadventently form new tokens
at the left and right edges.  For example:

   {|
   |<escaped string>

When the escaped string starts with a `-` or `+` it forms the `|-` or `|+`
token and changes the parse.

On the right side:

  <escaped string>_FORCETOC__

is not a magic word unless the escaped string ends with a `_`.

Token-gluing can also occur with the double newline token denoting
a paragraph separator.

This patch adds additional cases to wfEscapeWikiText to armor
its output against all contexts in which the output may be
inserted.

Depends-On: I56147520620d56a4b98c2f22d1f469b49aed761f
Change-Id: I34f2fa8c329e6f6771453b2f94dc4afbec31dac8
2024-01-26 17:48:46 -05:00
thiemowmde
a61078f653 Minimize code duplication in StatusValue methods
Use modern array destructuring and such to make the code – so I
hope – much more readable.

Also fix a mistake in the Status test setup. This caused the mocked
Message::getParams() to return an array with string keys. This is
impossible in non-mocked scenarios. There is an array_values() call
in the Message constructor that doesn't allow string keys.

Change-Id: Ief09feb06c60d3ffbfa95fa8ef56b4a9829da680
2023-11-30 20:26:52 +00:00
daniel
04197cb13f Introduce StatusFormatter
This takes us one step closer to deprecating Status,
so we can isolate StatusValue from presentation logic.

FormatterFactory is introduced as a mechanism for
getting instance of formatters that need access to the user interface
language and other request dependent information.

Usage is demonstrated in thumb.php, SpecialCreateAccount, and
SearchHandler. The examples indicates that there is no work do
be done around ErrorPageError and LocalizedHttpException.

Change-Id: I7fe5fee24cadf934e578c36856cc5d45fb9d0981
2023-10-27 14:56:51 +02: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
Umherirrender
790ae736c1 tests: Move test cases from /includes/ into sub folder
Follow move of the tested class
Most moves are part of T321882

Change-Id: I74ab45d6a5331dcb2ff0b65dc2cc7c6315146646
2023-09-13 00:09:05 +02:00
Renamed from tests/phpunit/includes/StatusTest.php (Browse further)