aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/languages/LanguageFiTest.php
diff options
context:
space:
mode:
authorMáté Szabó <mszabo@wikimedia.org>2025-03-10 16:35:29 +0100
committerMáté Szabó <mszabo@wikimedia.org>2025-03-10 16:51:33 +0100
commitff7b937f5276e97ef0db2707843635ea1601b84b (patch)
treeb4c7353d96bdc93877e949c76ea4683d2c6dc3c9 /tests/phpunit/includes/languages/LanguageFiTest.php
parente0c9c34cdf723a0671fce193198f3d2fca6eea7e (diff)
downloadmediawikicore-ff7b937f5276e97ef0db2707843635ea1601b84b.tar.gz
mediawikicore-ff7b937f5276e97ef0db2707843635ea1601b84b.zip
language: fix mw.language.convertGrammar with word-specific casing rules
Why: - mw.language.convertGrammar is responsible for implementing grammatical transformations for inflected languages, similar to its backend counterpart Language::convertGrammar. - The default implementation may be overridden by language-specific implementations loaded dynamically based on the user language. - Both the default implementation and all language-specific implementations suffer from a bug where requesting a case transformation for which word-specific casing rules are defined will return "undefined" if the case transformation was requested for a word for which no word-specific casing rule exists. - There are QUnit tests for the logic, but they only run if the user language matches the language being tested. This means they never run in CI and cannot even be run locally, since Special:JavaScriptTest has been forcing the user language to "qqx" for more than five years. What: - Place language-specific convertGrammar overrides into a new convertGrammarMapping property keyed by language code to allow loading more than one simultaneously. - Introduce and use a new 'mediawiki.language.grammar.testdata' test-only RL module that loads every language-specific convertGrammar override. - Introduce and use a new 'mediawiki.language.testdata' test-only RL module that loads language-specific rules for languages that we have QUnit tests for. Since this only covers less than two dozen languages, there'd be no value in loading this data for all 300+ languages supported by MediaWiki. - Update QUnit tests for convertGrammar to override the user language and language rules before each case. - Ensure word-specific casing rules always take precedence over language-specific convertGrammar implementations to avoid repeated boilerplate in language-specific code. - Don't attempt to use word-specific casing rules for words that do not have one. - As we're here, add matching PHPUnit tests for Language* subclasses that had preexisting QUnit tests but no PHPUnit tests. Bug: T388370 Change-Id: I3f2432f5f801c2a7e4390c2ff2038363a36e2ed9
Diffstat (limited to 'tests/phpunit/includes/languages/LanguageFiTest.php')
-rw-r--r--tests/phpunit/includes/languages/LanguageFiTest.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/phpunit/includes/languages/LanguageFiTest.php b/tests/phpunit/includes/languages/LanguageFiTest.php
new file mode 100644
index 000000000000..fb9efd76e493
--- /dev/null
+++ b/tests/phpunit/includes/languages/LanguageFiTest.php
@@ -0,0 +1,40 @@
+<?php
+declare( strict_types=1 );
+
+/**
+ * @group Language
+ * @covers LanguageFi
+ */
+class LanguageFiTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider provideConvertGrammar
+ */
+ public function testConvertGrammar( string $word, string $case, string $expected ): void {
+ $this->assertSame( $expected, $this->getLang()->convertGrammar( $word, $case ) );
+ }
+
+ public static function provideConvertGrammar(): iterable {
+ $wordCaseMappings = [
+ 'talo' => [
+ 'genitive' => 'talon',
+ 'elative' => 'talosta',
+ 'partitive' => 'taloa',
+ 'illative' => 'taloon',
+ 'inessive' => 'talossa',
+ ],
+ 'pastöroitu' => [
+ 'partitive' => 'pastöroitua',
+ ],
+ 'Wikipedia' => [
+ 'elative' => 'Wikipediasta',
+ 'partitive' => 'Wikipediaa',
+ ],
+ ];
+
+ foreach ( $wordCaseMappings as $word => $caseMappings ) {
+ foreach ( $caseMappings as $case => $expected ) {
+ yield "$word $case" => [ (string)$word, $case, $expected ];
+ }
+ }
+ }
+}