aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMisha M.-Kupriyanov <kupriyanov@strato.de>2024-03-15 10:40:54 +0100
committerMikhailo Matiyenko-Kupriyanov <145785698+printminion-co@users.noreply.github.com>2024-07-01 09:34:11 +0200
commitaceb4d776c48dbe46cf066c4688a190b153ed046 (patch)
tree94d0cd9dbb23bd42bba4b9de3022933a301e74c1 /tests
parentd5b7525e1fd2aa03f403a43a6b5b80b9e44e01da (diff)
downloadnextcloud-server-aceb4d776c48dbe46cf066c4688a190b153ed046.tar.gz
nextcloud-server-aceb4d776c48dbe46cf066c4688a190b153ed046.zip
feat: reduce available languages per config value "reduce_to_languages"
Example: restrict to en, de, es, fr, it' languages ./occ config:system:set reduce_to_languages 0 --value en ./occ config:system:set reduce_to_languages 1 --value de ./occ config:system:set reduce_to_languages 2 --value es ./occ config:system:set reduce_to_languages 3 --value fr ./occ config:system:set reduce_to_languages 4 --value it Signed-off-by: Misha M.-Kupriyanov <kupriyanov@strato.de>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/L10N/FactoryTest.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/lib/L10N/FactoryTest.php b/tests/lib/L10N/FactoryTest.php
index 771ce75d3e9..16113c0972f 100644
--- a/tests/lib/L10N/FactoryTest.php
+++ b/tests/lib/L10N/FactoryTest.php
@@ -700,6 +700,53 @@ class FactoryTest extends TestCase {
self::assertSame($expected, $result);
}
+ public static function dataTestReduceToLanguages(): array {
+ return [
+ ['en', ['en', 'de', 'fr', 'it', 'es'], ['en', 'fr', 'de'], ['en', 'fr', 'de']],
+ ['en', ['en', 'de', 'fr', 'it', 'es'], ['en', 'de'], ['en', 'de']],
+ ['en', ['en', 'de', 'fr', 'it', 'es'], [], ['de', 'en', 'es', 'fr', 'it']],
+ ];
+ }
+
+ /**
+ * test
+ * - if available languages set can be reduced by configuration
+ * - if available languages set is not reduced to an empty set if
+ * the reduce config is an empty set
+ *
+ * @dataProvider dataTestReduceToLanguages
+ *
+ * @param string $lang
+ * @param array $availableLanguages
+ * @param array $reducedLanguageSet
+ * @param array $expected
+ */
+ public function testReduceLanguagesByConfiguration(string $lang, array $availableLanguages, array $reducedLanguageSet, array $expected): void {
+ $factory = $this->getFactory(['findAvailableLanguages', 'languageExists']);
+ $factory->expects(self::any())
+ ->method('languageExists')->willReturn(true);
+ $factory->expects(self::any())
+ ->method('findAvailableLanguages')
+ ->willReturnCallback(function ($app) use ($availableLanguages) {
+ return $availableLanguages;
+ });
+
+ $this->config
+ ->method('getSystemValue')
+ ->willReturnMap([
+ ['force_language', false, false],
+ ['default_language', false, $lang],
+ ['reduce_to_languages', [], $reducedLanguageSet]
+ ]);
+
+ $result = $this->invokePrivate($factory, 'getLanguages');
+ $commonLanguagesCodes = array_map(function ($lang) {
+ return $lang['code'];
+ }, $result['commonLanguages']);
+
+ self::assertEqualsCanonicalizing($expected, $commonLanguagesCodes);
+ }
+
public function languageIteratorRequestProvider():array {
return [
[ true, $this->createMock(IUser::class)],