Commit graph

36 commits

Author SHA1 Message Date
Ebrahim Byagowi
697e19e461 Add MediaWiki\Registration namespace to registration classes
Bug: T353458
Change-Id: Ifa3b6a6e0353bb4ce21a3f4456f1fc696c8d377c
2024-08-10 10:08:22 +00:00
jenkins-bot
d18d0c2283 Merge "language: Widen @covers tags in phpunit tests" 2024-06-25 22:50:53 +00:00
Timo Tijhof
4160c223f2 language: Widen @covers tags in phpunit tests
Add a few missing `@group Language` tags as well.
Remove stray `@group Cache` from two classes since "Cache" is not a
MediaWiki core component (per T248519 and related tasks, we did long
ago in Bugzilla have a "MediaWiki-Cache" category, but that's since
been re-orged into BagOStuff, HTTP-Cache, and Parser/ParserCache,
and Internationalization/LocalisationCache, per the description at
<https://phabricator.wikimedia.org/project/profile/1329/>.)

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

> Given all called methods are de-facto and liberally claimed, and
> that we keep the coverage limited to the subject class, it maintains
> the spirit and intent by listing the class explicitly instead.
>
> PHPUnit offers a more precise tool when you need it (i.e. when testing
> legacy monster/god classes), but for well-written code, the
> class-wide tag is exactly what you want.
>
> 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".

Bug: T364652
Change-Id: I9cfc4c210b90bfed6fd988a2525f80f5f5ee4870
2024-06-25 18:51:54 +00:00
Ollie Shotton
e82ec6265c Improve human-readable duration in Language
by using the new `Language::formatDurationBetweenTimestamps()` method

Change-Id: I119f3916d4e3003e3d09817eb0eb3e61499292f6
2024-06-25 17:25:03 +00:00
jenkins-bot
780df68f9d Merge "Use upstream markTestSkippedIfExtensionNotLoaded in test" 2024-06-04 18:48:06 +00:00
Ollie Shotton
63d1ab6808 Add Language::formatDurationBetweenTimestamps method
which takes two timestamps in order to calculate a more accurate text representation of the duration between the timestamps

Bug: T219397
Co-authored-by: addshore <addshorewiki@gmail.com>
Co-authored-by: Silvan <silvan.heintze@wikimedia.de>
Change-Id: I290f8da815f9571dae75fddde2da2010cc9a7fec
2024-05-05 01:22:53 +01:00
addshore
3ab0eff2a6 Add months as duration to Language:formatDuration
I think there is further room for improvement
here, such as a method that takes 2 points in time
and gives you a more precise summarization of the duration
in terms of actual dates.
(And we will do this in a followup)

To avoid changing behaviour where this method is called
the default interval of `month` is not specified, so
existing calls return as they did before.
For callers that want `month` granularity, they can
specify month.

Bug: T219397
Change-Id: I5a07e14629fd9f67b1f17df3db75b68f98295dfb
2024-05-04 08:19:20 +03:00
thiemowmde
9d57dc8434 Use upstream markTestSkippedIfExtensionNotLoaded in test
Change-Id: Ifab541f7323163e98f23393eb2227240cebc0daf
2024-04-10 14:15:16 +02:00
Reedy
85396a9c99 tests: Fix @covers and @coversDefaultClass to have leading \
Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
2024-02-16 22:43:56 +00:00
rxy
9604fd122a Fix and split Japanese era related logic
Bug: T356419
Change-Id: I764dff7f0d2bcddb5668d8497d0fe66e3ef3bf21
2024-02-15 21:19:19 +00:00
Daimona Eaytoy
175c0c4abf Replace more instances of deprecated MWException
Bug: T328220
Change-Id: Iba90f7f9b5766bccc05380d040138d74d5e9558a
2024-01-19 23:11:59 +00:00
daniel
be754ece78 Improve layering: remove reference to SpecialBlock from Language
Special pages belong to the interaction layer, lower level code should
not access them. That is especially true for something used everywhere
in the code base, like Language.

Change-Id: I46a2a7d60ff73dac3ce72e657c6232b6168a98e8
2023-12-15 14:10:42 +00:00
Daimona Eaytoy
48a1c0bb2f Autofix spacing around commas
This was done automatically using the
`Universal.WhiteSpace.CommaSpacing` sniff, which will be included in the
next release of the MW PHPCS config.

Some of these have been adjusted manually where the autofix broke
vertical alignment.

Change-Id: I54a4668d8a2759b9d7de47742c943a535a04e211
2023-10-25 01:08:44 +02:00
Fomafix
42b0f55741 Use $this->getServiceContainer() in tests
Use
	$this->getServiceContainer()
instead of
	MediaWikiServices::getInstance()
in tests where possible.

Change-Id: I798b2941f37a43b9073072935b54c3ea0cfe70dd
2023-10-17 18:40:46 +00: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
Lucas Werkmeister
b47847e4c4 Fix LanguageIntegrationTest::testCldr()
On LanguageNameUtils, the method is called getLanguageName(), not
fetchLanguageName() like on Language.

As far as I can tell, this must have been broken since change
I016b1c1731 (commit 0f935809fd). It might have worked in MediaWiki core
CI because the cldr extension isn’t installed there (and thus the test
is skipped); I have no idea why it seemingly didn’t break cldr’s own CI;
but locally, the test consistently fails.

Bug: T325962
Change-Id: I0a2ff0a41ebe4f3007316e4511926f6b10c71e1d
2023-09-20 16:50:05 +02:00
James D. Forrester
a8a6cfd966 Namespace NamespaceInfo under \MediaWiki\Title
One of the big ones, so doing this alone.

Bug: T166010
Change-Id: Ibe103cd362535d3cb94cb8931e95fc74099d1497
2023-09-19 05:17:04 +00:00
Fomafix
0f935809fd Language: Remove deprecated functions and constants
The functions are hard deprecated since MediaWiki 1.40.

Bug: T343185
Bug: T325974
Bug: T325982
Bug: T325962
Bug: T325986
Bug: T325979
Bug: T325981
Bug: T252095
Change-Id: I016b1c173126ac8ff264918279d0c7912c428699
2023-08-06 00:53:30 +02:00
Tim Starling
772662378a Make minimumGroupingDigits an integer and add documentation
All Messages*.php variables are supposed to be documented in
MessagesEn.php.

I don't see the point in having Language::minimumGroupingDigits() return
null, and then expecting every caller to cast null to zero.

The default for English is properly 1, not 0, since 3-digit numbers do
not need grouping. We don't write 999 as ",999". Setting it to 1
instead of null should improve the performance of the JS commafyNumber()
by avoiding the unnecessary loop body. Change the QUnit test data to
confirm that this works.

In the PHP implementation, adjust the comparison to avoid the
preg_match() when minimumGroupingDigits is 1.

Change-Id: I6679d69e7094502303389039550e17a47189e2dc
2023-07-31 13:18:49 +10:00
Fomafix
458d319798 LanguageIntegrationTest: Replace call of deprecated Language::factory
Only update test cases that tests non-deprecated functions.
Test cases that tests deprecated functions can be removed together with
the removal of the deprecated functions.

Also consistently use
  $this->getServiceContainer()
instead of
  MediaWikiServices::getInstance()

Change-Id: Iac40d6c66a31dd699ab8771244c701232e4354e8
2023-07-17 18:59:56 +00:00
Daimona Eaytoy
0e55aa602a Inject extension namespaces into NamespaceInfo
The service was previously accessing the global ExtensionRegistry
singleton, making it lose its statelessness. Dependencies should always
be injected, so add constructor parameters for that.

Simplify tests accordingly.

Change-Id: Iae375a81cab411fab607cba0addb2088131b3c81
2023-07-16 22:53:26 +02:00
daniel
63a610b8c7 Deprecate HookContainer::getHandlerCallbacks
There should be no need to call hook handlers directly,
this should only be done by HookContainer.

Change-Id: I8fa46c2eb6a40ad98e564c31dcfb103825608426
2023-06-23 00:26:40 +00:00
Lucas Werkmeister
5f2bfc44ce Simplify HookContainer (v2)
This reverts change I50c3d1c5df (commit b0317287bc), thus reinstating
change I7d690a1172 (commit d139eb07fe). The only change from the
original is in getHookMethodName(), additionally replacing '-' with '_'
(not just ':' and '\'). The original commit message follows:

This converts all hook handlers to the same internal representation.
This is done lazily, when the hook is run for the first time.

The logic for temporarily disabling handlers by calling scopedRegister()
with the $replace parameter set has been greatly simplified.

There are some minor changes to the class's interface and behavior,
none of which should be breaking changes:
* run() will emit deprecation warnings if and only if it was called
  with the deprecationVersion option set, for all kinds of handlers.
  The idea is that deprecated hooks should emit a warning either from
  run(), or from emitDeprecationWarnings(). The latter happens if the
  hook is listed in DeprecatedHooks.
* register() now also accepts hook handlers declared in the way that
  extensions register hooks.
* Attempts to call register() with an invalid hook definition now
  result in an invalidArgumentException.
* Attempts to call register() for a deprecated hook will consistently
  result in a deprecation warning.
* The internal getRegisteredHooks() method has been removed in favor
  of the identical getHookNames() method.
* The internal getLegacyHandlers method has been removed in favor
  of getHandlerDescriptions() and getHandlerCallbacks().
* The call order changed so that dynamically registered handlers
  are called last, instead of getting called before handler objects
  from extensions.

Bug: T338213
Change-Id: I6efb09e314ad2b124a33a757fdda2a07ae0d8f7c
2023-06-06 12:06:23 +02:00
Lucas Werkmeister
b0317287bc Revert "Simplify HookContainer"
This apparently caused some change in how hook handlers are called (it
now calls e.g.  AbuseFilterHookHandler::onAbuseFilter-generateUserVars()
instead of AbuseFilterHookHandler::onAbuseFilter_generateUserVars()),
causing both test failures and errors on Beta.

This reverts commit d139eb07fe.

Bug: T338213
Change-Id: I50c3d1c5dfd2d7eeac59992156a8a644cf0197e5
2023-06-06 11:12:18 +02:00
daniel
d139eb07fe Simplify HookContainer
This converts all hook handlers to the same internal representation.
This is done lazily, when the hook is run for the first time.

The logic for temporarily disabling handlers by calling scopedRegister()
with the $replace parameter set has been greatly simplified.

There are some minor changes to the class's interface and behavior,
none of which should be breaking changes:
* run() will emit deprecation warnings if and only if it was called
  with the deprecationVersion option set, for all kinds of handlers.
  The idea is that deprecated hooks should emit a warning either from
  run(), or from emitDeprecationWarnings(). The latter happens if the
  hook is listed in DeprecatedHooks.
* register() now also accepts hook handlers declared in the way that
  extensions register hooks.
* Attempts to call register() with an invalid hook definition now
  result in an invalidArgumentException.
* Attempts to call register() for a deprecated hook will consistently
  result in a deprecation warning.
* The internal getRegisteredHooks() method has been removed in favor
  of the identical getHookNames() method.
* The internal getLegacyHandlers method has been removed in favor
  of getHandlerDescriptions() and getHandlerCallbacks().
* The call order changed so that dynamically registered handlers
  are called last, instead of getting called before handler objects
  from extensions.

Change-Id: I7d690a1172af44a90b957b2274d68e51b7f09938
2023-06-04 15:36:38 +02:00
Umherirrender
d36073cdcf tests: Make some PHPUnit data providers static
Initally used a new sniff with autofix (T333745),
but some provide are defined non-static in TestBase class
and need more work to make them static in a compatible way

Bug: T332865
Change-Id: I889d33424f0c01fb26f2d86f8d4fc3de3e568843
2023-05-20 01:05:27 +02:00
Tim Starling
d36ea70309 Fix some PHPStorm inspections (#1)
* Triple backslash in regex should really be quadruple backslash
* Using the returned value of a void method
* Immediately overwritten array keys
* Duplicate array keys
* Foreach variable reuse
* sprintf() with too many params
* Incorrect reference usage

Change-Id: I3c649b543c9561a1614058c50f3847f663ff04df
2023-03-25 00:19:33 +00: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
jenkins-bot
2e6f8c18e6 Merge "Language: Hard-deprecate Language::factory/getParentLanguage" 2023-03-10 17:03:37 +00:00
jenkins-bot
9213528d05 Merge "Remove deprecated Language::commafy and mw.language.commafy" 2023-03-10 16:56:06 +00:00
Fomafix
7f4e9bfa39 Remove deprecated Language::commafy and mw.language.commafy
Language::commafy and mw.language.commafy have been deprecated in
4bc5c761 included in MW 1.36.

Bug: T331708
Change-Id: I874c2c904fa4a7f04486113d1d92709c21d1f5bb
2023-03-10 15:16:06 +00:00
daniel
d19f30cede Tests: treat wgHooks like a regular config variable.
Prepare phpunit tests for a world where $wgHooks behaves like other
config variables: on-the-fly manipulation doesn't have an effect,
service objects need to be reset after changing it.

Change-Id: I34385f4c52febfe1c91bd7ea4100c06d1331adc8
2023-03-09 12:25:46 +11:00
Umherirrender
e6bd6d225e Language: Hard-deprecate Language::factory/getParentLanguage
- Language::getParentLanguage
- Language::factory

Bug: T325986
Change-Id: I0077630232587860ea4c7e37790cb24fc17f6e92
2023-03-02 23:18:27 +01:00
Umherirrender
0ccde3720d Language: Hard-deprecate language converter functions, deprecated in 1.35
These are:
- Language::getConverter()
- Language::autoConvert()
- Language::autoConvertToAllVariants()
- Language::convert()
- Language::convertNamespace()
- Language::convertHtml()
- Language::convertCategoryKey()
- Language::getVariants()
- Language::hasVariants()
- Language::hasVariant()
- Language::getDefaultVariant()
- Language::getURLVariant()
- Language::getExtraHashOptions()
- Language::getConvRuleTitle()

Bug: T252095
Change-Id: I810e90b43ba112b868821c811c51b5532800765f
2023-03-02 21:13:16 +00:00
DannyS712
a5293c323a Tests: add LanguageNameUtils to DummyServicesTrait
Returns a real LanguageNameUtils object configured as needed.

Change-Id: I50a8c6bc15665c454642a513f6669191456a3939
2023-02-02 20:50:48 +00:00
Umherirrender
9bcd6f7f80 tests: Move all language converter tests into /includes/
Move tests from /languages/ to /includes/language/ similiar to the
classes in f5644ba
Clean up suite config too not longer run that folder as test,
remove from coverage, there no php files to cover

Remove converter tests from Language*Test files,
all identical to the *ConverterTest cases (or remove the whole file)

Change-Id: I098ba241bd61d8ed2ee9b65393416077e3544e79
2023-02-01 20:10:56 +01:00
Renamed from tests/phpunit/languages/LanguageIntegrationTest.php (Browse further)