Commit graph

45 commits

Author SHA1 Message Date
Acamicamacaraca
a573bea01b Implement LanguageConverter for sh.wiki
This patch will implement a one-way transliterator (Latin->Cyrillic), per community consensus.

Bug: T268033
Change-Id: I6f3e7efe3630e9960584dca3a5ee55cb92ea722c
Co-Authored-By: Deni <deni@deni.dk>
Co-Authored-By: Winston Sung <winston21.sung@gmail.com>
2022-11-15 06:29:11 +00:00
daniel
8c1c1ae35a Enable pig-latin variant for testing
Having pig-latin enabled per default in dev environments is convenient
for manual testing. More importantly, it will allow us to write
end-to-end tests for variant conversion.

Depends-On: I9dc2f743ac487b0f7cfb667150c0f6950d5e7fce
Depends-On: I85b66c85be3959d48a048733af17197bc4cf70af
Change-Id: Ia80ad33cbf5e311fa8b84bd765a8df8d156f4c38
2022-11-08 17:45:51 +05:30
jenkins-bot
a85966542d Merge "Use short array destructuring instead of list()" 2022-10-21 11:11:06 +00:00
Tim Starling
0077c5da15 Use short array destructuring instead of list()
Introduced in PHP 7.1. Because it's shorter and looks nice.

I used regex replacement.

Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
2022-10-21 15:33:37 +11:00
Tim Starling
43a93d9782 Use the null coalescing assignment operator
Available since PHP 7.4.

Automated search, manual replacement.

Change-Id: Ibb163141526e799bff08cfeb4037b52144bb39fa
2022-10-21 13:26:49 +11:00
C. Scott Ananian
e185a570ae Add efficient LanguageCode::bcp47ToInternal() helper
LanguageFactory::getLanguage() will accept *lowercased* BCP-47 codes, so
this method is equivalent to
  LanguageFactory::getLanguage(strtolower($code))->getCode()
but should be much more efficient in practice.

Change-Id: I180765604d08ed57f655b69dfb32686f0b2a0dce
2022-10-20 10:11:14 -04:00
Fomafix
b50aa1a47d Add 'zh-classical' to the test cases for isWellFormedLanguageTag
This shows that 'zh-classical' is not even a well-formed language tag
because 'classical' has more than 8 characters.

Change-Id: Ic07baf98ca4d92fa4c196895533650145c440584
2022-08-31 20:15:00 +00:00
Fomafix
233677a9a5 Move isWellFormedLanguageTag from Language to LanguageCode
The static function isWellFormedLanguageTag is related to BCP 47
language codes not to the internal language codes or language names.

The new function LanguageCode::isWellFormedLanguageTag uses type hints.
THe explicit type cast (bool) is not necessary anymore.

The old function Language::isWellFormedLanguageTag is now deprecated.

Change-Id: I6431dbd82ed6dfcc2a7c3495eca025506551db05
2022-08-30 11:39:26 +00:00
Umherirrender
167fb2a979 unit tests: Use MainConfigNames constant to refer configs
When creating ServiceOptions objects or fake HashConfigs use the
constant to refer the config name

Change-Id: I59a29f25b76e896c07e82156c6cc4494f98e64cc
2022-08-17 22:33:58 +02:00
jenkins-bot
8de0be85a4 Merge "Step 1 of renaming sr-ec and sr-el to sr-cyrl and sr-latn" 2022-07-20 22:31:39 +00:00
Thiemo Kreuz
3703b30618 Tests: Use createNoOpMock() shortcut in a few more places
… instead of doing the same manually with anythingBut() and such.

Change-Id: Idb66040d1560a82df9a5bfa2a6c7e20a0649e49c
2022-07-18 21:25:31 +00:00
Fomafix
6839b85994 Step 1 of renaming sr-ec and sr-el to sr-cyrl and sr-latn
The language codes sr-ec and sr-el are not conform to BCP 47.
BCP 47 explicit mentions sr-Latn and sr-Cyrl as examples.

This change adds support for the language codes sr-cyrl and sr-latn
as fallback languages of the language codes sr-ec and sr-el. This
allows to rename the message files and the system messages without
changing the language codes yet.

The next step is to rename the language codes in Translatewiki as
described in https://translatewiki.net/wiki/Renaming_language_codes
Also local system messages in MediaWiki:*/sr-ec and MediaWiki:*/sr-el
can moved to MediaWiki:*/sr-cyrl and MediaWiki:*/sr-latn.

The final step is the change I75da0af35a2066e7963e50c56c99daf1e07c55e6
to complete the rename of the language codes.

Bug: T117845
Change-Id: I666fbdea89ccf21aab6ca1849adf22813dec052e
2022-07-10 21:19:34 +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
128debb64b tests: Change use of AtEase to at operator
Follows-up I361fde0de7f4406bce6ed075ed397effa5be3359.

Per T253461, not mass-changing source code, but the use of the native
error silencing operator (@) is especially useful in tests because:

1. It requires any/all statements to be explicitly marked. The
   suppressWarnings/restoreWarnings sections encourage developers to
   be "lazy" and thus encapsulate more than needed if there are multiple
   ones near each other, which would ignore potentially important
   warnings in a test case, which is generally exactly the time when
   it is really useful to get warnings etc.

2. It avoids leaking state, for example in LBFactoryTest the
   assertFalse call would throw a PHPUnit assertion error (not meant
   to be caught by the local catch), and thus won't reach
   AtEase::restoreWarnings. This then causes later code to end up
   in a mismatching state and creates a confusing error_reporting
   state.

See .phpcs.xml, where the at operator is allowed for all test code.

Change-Id: I68d1725d685e0a7586468bc9de6dc29ceea31b8a
2022-02-24 21:29:51 +00: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
Alexander Vorwerk
3aa5b6643b Use LanguageNameUtils constants instead of strings
Change-Id: I8521d00675008da0d7c8c768ab75352212653c66
2021-12-05 22:13:34 +01:00
Umherirrender
baf4d01efa build: Suppress ObjectTypeHintReturn for upcoming sniff change
The abstract function gets validated with a new version of codesniffer
(since I4a17c2d965c277e7f8862e0e98228839022e0a01),
suppress the new error for the future version

Change-Id: I48c9151d24306822113c0305133a4984a8391f02
2021-08-05 23:01:55 +00: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
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
Reedy
eb41565a9a Tests: Start marking some closures as static
Bug: T274036
Change-Id: Ib738ecd3bc23d34900bc268c8246702ac3655746
2021-02-06 19:57:42 +00:00
Umherirrender
393b6fb508 Add missing @param tags in tests
And exclude the rest inline to remove global exclude

Bug: T238572
Change-Id: Ib4c207177dd73702c113e6233f59be6e571a0f6a
2021-02-01 20:38:05 +01: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
DannyS712
6a93b0ca93 More misc test cleanup
* parent::setUp() should be first, and ::tearDown()
  should be last
* Move tests that directly extend PHPUnit\Framework\TestCase
  to /unit

Change-Id: I1172855c58f4f52a8f624e6d596ec43beb8c93ff
2020-12-24 00:52:06 +00:00
Umherirrender
2579ca623a build: Updating mediawiki/mediawiki-codesniffer to 34.0.0
Change-Id: I2fb18ddd4c144655a665792901e59f88bcd906dc
2020-12-07 14:55:24 +01:00
Kosta Harlan
508d3a0227 phpunit: Switch SpecialPageAliasTest to integration tests
As its comment notes, this is more of a structure test anyway.

Bug: T266441
Change-Id: I83bd577674ad65d7b90c93559dd5223164336a24
2020-11-19 13:36:09 +00:00
Daimona Eaytoy
95e17ee645 Fix some unit tests accessing MediaWikiServices
These are mostly easy fixes. Tests were fixed when that didn't require
any change to the tested code, and moved to /integration otherwise.

MediaWikiUnitTestCase::setTemporaryHook was removed: the
caller should provide a HookContainer, at which point it would just
become a useless wrapper around HookContainer::register. (We don't
really need it to be temporary, if proper DI is used).
The method was only used in the tests touched by this commit.

Change-Id: I2aba02560c41b77eea9dd4bff0e4d1c4bb0da9a2
2020-11-12 19:13:47 +00:00
Ed Sanders
9e5ba1f4f8 Fix switch/case indentation per mediawiki coding conventions
See https://www.mediawiki.org/wiki/Manual:Coding_conventions#Indenting_and_alignment

Bug: T182546
Change-Id: Ia0dedba6f4676f3c703e3416858f445e4ade4ef6
2020-07-18 09:17:46 +00:00
Tim Starling
68c433bd23 Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.

General principles:
* Use DI if it is already used. We're not changing the way state is
  managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
  is a service, it's a more generic interface, it is the only
  thing that provides isRegistered() which is needed in some cases,
  and a HookRunner can be efficiently constructed from it
  (confirmed by benchmark). Because HookContainer is needed
  for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
  SpecialPage and ApiBase have getHookContainer() and getHookRunner()
  methods in the base class, and classes that extend that base class
  are not expected to know or care where the base class gets its
  HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
  getHookRunner() methods, getting them from the global service
  container. The point of this is to ease migration to DI by ensuring
  that call sites ask their local friendly base class rather than
  getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
  methods did not seem warranted, there is a private HookRunner property
  which is accessed directly. Very rarely (two cases), there is a
  protected property, for consistency with code that conventionally
  assumes protected=private, but in cases where the class might actually
  be overridden, a protected accessor is preferred over a protected
  property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
  global code. In a few cases it was used for objects with broken
  construction schemes, out of horror or laziness.

Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore

Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router

setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine

Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-05-30 14:23:28 +00:00
Reedy
ead6b1e53f Fix some PSR12.Properties.ConstantVisibility.NotFound in tests/phpunit/
Change-Id: I0f678049dc274f0cd29f543bb293c33da51d8529
2020-05-09 23:55:09 +00:00
Timo Tijhof
161fab3a9c language: Avoid LCStoreStaticArray::decode() recursion for arrays
In looking at early flame graphs and XHGui profiles, I noticed
code paths like `decode -> decode@2 -> decode@3`, for example for
magic words arrays and special page names.

Rather than storing these as `[a, [a, [a, ..], [a, ..], [a, ..], .. ] ]`
store them instead as `[v, [ .. ]]`. This makes for smaller files,
but more important it further reduces runtime overhead.

Bug: T218207
Change-Id: I492e5d32106ba7fd1b22075cf026fee2e3d1944e
2020-05-04 17:46:04 +01:00
Timo Tijhof
08791d1c1d language: Add test coverage for LCStoreStaticArray
Bug: T218207
Change-Id: I2e4c95139153f206b5317a4efe1e9b324ecce225
2020-05-04 17:34:21 +01:00
Max Semenik
09f2feafd6 tests: Make static/non-static functions match
PHP 8 is stricter about this.

Bug: T248925
Change-Id: I0e9c736d0e2a28ce4a1e096a8ec63321d8b41635
2020-04-29 10:59:53 +03:00
Thiemo Kreuz
c05bdcee8b Remove unreachable null checks after isset()
isset() does two things: It checks if a variable (or array element)
is declared, *and* it checks if it is null. If a variable is null,
isset() fails as if the variable was not set. All these additional
null checks are dead code.

Change-Id: I71e8cc26dac839c9d081bf00b4164b7b5147e586
2020-02-28 21:40:48 +00:00
Daimona Eaytoy
6365eaab8d Autofix 94 PHPUnit 8 compat issues
Done automatically using the master version of MW codesniffer and
running composer fix.

Bug: T192167
Change-Id: If6b40f515fde32ab5eff074a90e821c30c791827
2019-12-13 15:29:10 +01:00
Max Semenik
8dc97df794 tests: Nuke last usages of setExpectedException()
Bug: T192167
Change-Id: Ie34ef58841bf18ad4110ea4b3c54fc352d4085ec
2019-10-13 22:12:34 -07:00
James D. Forrester
b83a3e3e3a Follow-up Ifa346c8a92: LanguageNameUtils: CONSTRUCTOR_OTPIONS, not constructorOptions
Change-Id: I357dddf39834e9eed4b173245033d2f27edab329
2019-10-10 17:01:49 -07:00
Aryeh Gregor
8c4f59db64 New LanguageFallback service
This replaces the static Language methods getFallbackFor(),
getFallbacksFor(), and getFallbacksIncludingSiteLanguage(). There is
100% unit and integration test coverage for the new class.

One deliberate functional change: I changed one place where we threw
MWException to InvalidArgumentException.

Bug: T201405
Depends-On: Ie7a89f6ed7d52a0bc01672019ff92e7ee105a1f3
Change-Id: I49222eb55f1feec5b1dcd40f364cffe0c8801855
2019-10-08 15:11:39 -07:00
Aryeh Gregor
6d80b6c082 Split some Language methods to LanguageNameUtils
These are static methods that have to do with processing language names
and codes. I didn't include fallback behavior, because that would mean a
circular dependency with LocalisationCache.

In the new class, I renamed AS_AUTONYMS to AUTONYMS, and added a class
constant DEFINED for 'mw' to match the existing SUPPORTED and ALL. I
also renamed fetchLanguageName(s) to getLanguageName(s).

There is 100% test coverage for the code in the new class.

This was previously committed as 2e52f48c2e and reverted because it
depended on e4468a1d6b, which had to be reverted for performance
issues. There should be no changes other than rebasing.

Bug: T201405
Change-Id: Ifa346c8a92bf1eb57dc5e79458b32b7b26f1ee8a
2019-10-07 15:20:52 -07:00
Max Semenik
b0a8b0d275 Cleanup of old PHPUnit usage, part 3
Bug: T192167
Bug: T234597
Change-Id: I88a1ced51d7b57bc683de4a58bbeaa1537762113
2019-10-05 00:00:45 -07:00
Thiemo Kreuz
c2211946f7 tests: Replace PHPUnit's loose assertEquals(null) with assertNull()
assertEquals( null, … ) still succeeds when the actual value is 0, false,
an empty string, even an empty array. All these should be reported as a
failure, I would argue.

Note this patch previously also touched assertSame( null ). I reverted
these. The only benefit would have been consistency within this codebase,
but there is no strict reason to prefer one over the other. assertNull()
and assertSame( null ) are functionally identical.

Change-Id: I92102e833a8bc6af90b9516826abf111e2b79aac
2019-09-27 19:15:38 +00:00
Aryeh Gregor
97b9dbc6ce Integration tests for Language fallback methods
100% coverage.  Next: reimplementation as a service, and tests for the
new service.

Change-Id: Icdd5b84eb91fc83905209ce08d499011f7288e33
2019-08-29 18:25:12 +03:00
Amir Sarabadani
308e6427ae Revert "Make LocalisationCache a service"
This reverts commits:
 - 76a940350d
 - b78b8804d0
 - 2e52f48c2e
 - e4468a1d6b

Bug: T231200
Bug: T231198
Change-Id: I1a7e46a979ae5c9c8130dd3927f6663a216ba753
2019-08-26 18:28:26 +02:00
Aryeh Gregor
2e52f48c2e Split some Language methods to LanguageNameUtils
These are static methods that have to do with processing language names
and codes. I didn't include fallback behavior, because that would mean a
circular dependency with LocalisationCache.

In the new class, I renamed AS_AUTONYMS to AUTONYMS, and added a class
constant DEFINED for 'mw' to match the existing SUPPORTED and ALL. I
also renamed fetchLanguageName(s) to getLanguageName(s).

There is 100% test coverage for the code in the new class.

Change-Id: I245ae94bfc1f62b6af75ea57525139adf2539fe6
2019-08-23 12:52:35 +03:00
Timo Tijhof
6284ed6971 tests: Move unit/languages to unit/includes/language
These source classes they test were also moved from
languages/ to includes/languages/.

Bug: T225756
Change-Id: I6931d459bbfa243d2a28f391f92bce70f1e52256
2019-07-15 00:16:44 +01:00