19declare(strict_types=1);
28use PHPUnit\Framework\Attributes\DataProvider;
29use PHPUnit\Framework\MockObject\Stub;
34 use InstallLanguageTestFixture;
38 $setup_language = $this->createSetupLanguageStub([
'de'], [], []);
39 $setup_language->method(
'checkLanguageForInstallation')->willReturn(
true);
51 $setup_language = $this->createSetupLanguageMock([], [], [], [
'ilias_de.lang.locl']);
52 $setup_language->expects($this->once())
53 ->method(
'getInvalidLocalLanguageFiles')
55 ->willReturn([
'ilias_de.lang.locl']);
56 $setup_language->expects($this->once())
57 ->method(
'checkLanguageForInstallation')
60 $setup_language->expects($this->once())->method(
'flushLanguageForInstallation');
61 $setup_language->expects($this->once())->method(
'insertLanguageForInstallation');
64 'language_keys' =>
'de',
68 $this->assertSame([
'de'], $result[
'installed_language_keys']);
69 $this->assertSame([
'ilias_de.lang.locl'], $result[
'invalid_local_language_files']);
74 $setup_language = $this->createSetupLanguageMock([], [], []);
75 $setup_language->expects($this->once())
76 ->method(
'checkLanguageForInstallation')
79 $setup_language->method(
'getInstallableLanguagesForInstallation')->willReturn([
'xx']);
80 $setup_language->expects($this->never())->method(
'flushLanguageForInstallation');
81 $setup_language->expects($this->never())->method(
'insertLanguageForInstallation');
83 $this->expectException(InvalidLanguageFilesException::class);
84 $this->expectExceptionCode(409);
86 'language_keys' =>
'xx',
93 $setup_language = $this->createSetupLanguageMock([], [], []);
94 $setup_language->expects($this->exactly(2))
95 ->method(
'checkLanguageForInstallation')
100 $setup_language->method(
'getInstallableLanguagesForInstallation')->willReturn([
'de',
'xx']);
101 $setup_language->expects($this->never())->method(
'flushLanguageForInstallation');
102 $setup_language->expects($this->never())->method(
'insertLanguageForInstallation');
104 $this->expectException(InvalidLanguageFilesException::class);
105 $this->expectExceptionCode(409);
107 'language_keys' =>
'de,xx',
114 $setup_language = $this->createSetupLanguageMock([], [], []);
115 $setup_language->method(
'checkLanguageForInstallation')->willReturn(
false);
116 $setup_language->method(
'getInstallableLanguagesForInstallation')->willReturn([
'de']);
117 $setup_language->expects($this->never())->method(
'flushLanguageForInstallation');
118 $setup_language->expects($this->never())->method(
'insertLanguageForInstallation');
122 'language_keys' =>
'qq',
125 $this->fail(
'InvalidInputException expected');
127 $this->assertSame(400,
$e->getCode());
128 $this->assertSame(
'Unknown languages: qq',
$e->getMessage());
135 $setup_language = $this->createSetupLanguageMock([], [], []);
136 $setup_language->method(
'checkLanguageForInstallation')->willReturnMap([
141 $setup_language->method(
'getInstallableLanguagesForInstallation')->willReturn([
'de',
'xx']);
142 $setup_language->expects($this->never())->method(
'flushLanguageForInstallation');
143 $setup_language->expects($this->never())->method(
'insertLanguageForInstallation');
147 'language_keys' =>
'de,xx,qq',
150 $this->fail(
'InvalidInputException expected');
152 $this->assertSame(400,
$e->getCode());
153 $this->assertSame(
'Unknown languages: qq',
$e->getMessage());
163 $setup_language = $this->createSetupLanguageMock([], [], [
'de',
'fr']);
164 $setup_language->expects($this->exactly(2))
165 ->method(
'checkLanguageForInstallation')
170 $setup_language->method(
'getInstallableLanguagesForInstallation')->willReturn([
'fr']);
171 $setup_language->expects($this->never())->method(
'insertLanguageForApplyingLocalChanges');
172 $setup_language->expects($this->never())->method(
'registerInstalledLanguage');
176 'language_keys' =>
'de,fr,qq',
179 $this->fail(
'InvalidLanguageFilesException expected');
181 $this->assertSame(409,
$e->getCode());
182 $this->assertSame([
'de'],
$e->getLanguageKeys());
188 $this->expectException(InvalidInputException::class);
190 $this->
createActivity($this->createSetupLanguageStub([], [], []))->perform([
191 'language_keys' =>
'de',
197 $this->expectException(InvalidInputException::class);
199 $this->
createActivity($this->createSetupLanguageStub([], [], []))->perform([
200 'language_keys' =>
'de',
207 $text = $this->createMock(Text::class);
208 $text->expects($this->once())->method(
'withRequired')->with(
true)->willReturnSelf();
209 $text->expects($this->once())
210 ->method(
'withDedicatedName')
211 ->with(
'language_keys')
214 $select = $this->createMock(Select::class);
215 $select->expects($this->once())->method(
'withRequired')->with(
true)->willReturnSelf();
216 $select->expects($this->once())
217 ->method(
'withDedicatedName')
222 $field->expects($this->once())->method(
'text')->with(
224 'Comma-separated list of language keys, e.g. de, fr, it.'
225 )->willReturn(
$text);
226 $field->expects($this->once())->method(
'select')->with(
232 self::callback(
static fn(mixed $value):
bool => is_string($value))
233 )->willReturn($select);
236 $field->expects($this->once())
238 ->with([
'language_keys' =>
$text,
'mode' => $select], $this->anything())
239 ->willReturn($group);
242 $this->createSetupLanguageStub([], [], [])
245 $this->assertSame($group, $activity->getInputDescription($field));
251 'empty (only whitespace/commas)' => [
254 'nested array value' => [
267 'contains a digit' => [
270 'contains a hyphen' => [
276 #[DataProvider('invalidLanguageKeysProvider')]
279 $this->expectException(InvalidInputException::class);
287 $this->expectException(InvalidInputException::class);
289 $this->
createActivity($this->createSetupLanguageStub([], [], []))->perform(
'not-an-array');
295 $rbac = $this->createStub(\ilRbacSystem::class);
296 $rbac->method(
'checkAccessOfUser')->willReturn(
true);
298 $setup_language = $this->createSetupLanguageMock([], [], []);
299 $setup_language->method(
'checkLanguageForInstallation')->willReturn(
true);
300 $setup_language->expects($this->exactly(2))->method(
'flushLanguageForInstallation');
301 $setup_language->expects($this->exactly(2))->method(
'insertLanguageForInstallation');
303 $result = $this->
createActivity($setup_language, $rbac)->maybePerformAs(
304 $this->createRealFieldsUiFactory()->input(),
309 $this->assertTrue($result->isOk());
310 $this->assertSame([
'de',
'fr'], $result->value()[
'installed_language_keys']);
315 $rbac = $this->createMock(\ilRbacSystem::class);
316 $rbac->expects($this->once())
317 ->method(
'checkAccessOfUser')
325 $setup_language = $this->createSetupLanguageMock([], [], []);
326 $setup_language->expects($this->never())->method(
'getAvailableLanguagesForInstallation');
332 $this->assertTrue($result->isError());
const string MODE_INSTALL_LOCAL
const string MODE_INSTALL
A state of the server, not of the call: 409, so Failure::of() passes it on and the GUI can name the l...
testMaybePerformAsAcceptsAnArrayOfLanguageKeysAndInstallsEachOne()
ilObjLanguageFolderGUI sends 'language_keys' as array of strings; the real grind() pipeline must join...
testUnknownAndInvalidLanguagesTogetherAreRejectedAsInvalidInput()
The unknown language decides: the caller has to fix its input first.
testMissingModeParameterIsRejected()
testUnknownLanguageIsRejectedAsInvalidInputWithoutMutation()
testNonArrayParametersAreRejected()
Pins InvalidInputException, not just its parent \InvalidArgumentException.
testPermissionDeniedBeforePerform()
testInstallLocalModeWithAnInvalidLanguageFileIsReportedAsActivityErrorWithoutWriting()
"install_local" merges the shipped files too: an invalid one of an installed language rejects the req...
testInvalidLanguageKeysAreRejected(array $parameters)
testMixedValidAndInvalidLanguagesDoNotMutate()
testInvalidLanguageFileIsReportedAsActivityError()
static invalidLanguageKeysProvider()
testInvalidModeValueIsRejected()
testInputDescriptionUsesNamedLanguageKeysAndModeFields()
testMalformedLocalLanguageFileDoesNotPreventStandardInstallation()
language handling for setup
This describes text inputs.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
createActivity(\Closure $lng_objects, \Closure $obj_language_factory, ?\ilRbacSystem $rbac=null, int $language_folder_ref_id=0, ?RepositoryProvider $repository=null,)
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.