BCP 47 language tags are case insensitive. At the moment,
isWellFormedLanguageTag() lowercases the language tag to be checked, but
the regex contains uppercase characters, which means it will incorrectly
return false for a language tag like "en-GB-oed".
This changes the regex to use lowercase letters throughout, for
consistency, since it doesn't use capital letters in other places where
they would normally be used, but also makes it do a case-insensitive
match instead of trying to make sure the case for the regex and language
tag are the same. This should reduce the chance of it breaking if
someone later re-adds capital letters to the regex.
Change-Id: Iacf87d37c7ac515c350399f99e05e3f5bace9b90
This nominally takes a string-valued language code conforming to the
BCP-47 standard, but this is often generated from a Bcp47Code object.
Since the MediaWiki Language code implements Bcp47Code, we may have
the case where we have a Language object in hand (but typed as a
Bcp47Code not Language) and call Language::toBcp47Code() only to pass
it to LanguageCode::bcp47ToInternal to convert it back to a
mediawiki-internal code.
We can save steps and be more efficient if allow the parameter to be a
Bcp47Code object, and write a fast path for the special case where
that Bcp47Code happens to be a Language object and we can simply call
Language::getCode() to obtain the internal code.
Change-Id: I24932449b8c40e3a5072748d87667184f4befa67
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
This shows that 'zh-classical' is not even a well-formed language tag
because 'classical' has more than 8 characters.
Change-Id: Ic07baf98ca4d92fa4c196895533650145c440584
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
Done automatically using the master version of MW codesniffer and
running composer fix.
Bug: T192167
Change-Id: If6b40f515fde32ab5eff074a90e821c30c791827
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
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
Renamed from tests/phpunit/unit/languages/LanguageCodeTest.php (Browse further)