ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
InstalledLanguageDatabaseRepositoryTest Class Reference

Database-backed methods run against an ilDBInterface mock returning controlled rows; filesystem-backed methods use a real temporary installation root, like LanguageInstallationManagerTest. More...

+ Inheritance diagram for InstalledLanguageDatabaseRepositoryTest:
+ Collaboration diagram for InstalledLanguageDatabaseRepositoryTest:

Public Member Functions

 testGetAvailableLanguagesMapsObjIdAndStatusToTheCorrectLanguageNotSwapped ()
 
 testGetAvailableLanguagesReturnsEmptyArrayWhenNoLanguagesAreKnown ()
 
 testGetInstalledLanguagesQueriesForInstalledPrefixAndReturnsTitles ()
 
 testGetInstalledLocalLanguagesQueriesForExactlyInstalledLocalAndReturnsTitles ()
 
 testGetLocalChangesDefaultsMinAndMaxDateWhenEmptyStringsArePassed ()
 
 testGetLocalChangesKeepsExplicitlyGivenDatesInsteadOfDefaulting ()
 
 testGetLocalChangesStructuresResultAsModuleThenIdentifierThenValue ()
 
 testGetLocalChangesReturnsEmptyArrayWhenNothingMatches ()
 
 testGetLanguageEntriesStructuresResultAsModuleThenIdentifierThenValue ()
 
 testGetLanguageEntriesReturnsEmptyArrayWhenNothingMatches ()
 
 testGetLanguageEntriesQueryDoesNotFilterByLocalChange ()
 Unlike getLocalChanges(), getLanguageEntries() returns every stored entry of the language key, so its query must not filter on local_change. More...
 
 testGetLocalLanguagesExtractsKeysFromLocalFilesAndIgnoresUnrelatedFiles ()
 
 testGetLocalLanguagesIgnoresFilesWithAnInvalidLanguageKeyShapeInTheirName ()
 The discovery regex must accept exactly ParsesLanguageKeyList::LANGUAGE_KEY_FORMAT ('/^[a-z]{2}$/'): other file names must be ignored, or they would fail later in the Activity's stricter validation. More...
 
 testGetInstallableLanguagesIgnoresFilesWithAnInvalidLanguageKeyShapeInTheirName ()
 Same for getInstallableLanguages() (lang/) instead of getLocalLanguages() (lang/customizing/). More...
 
 testGetInstallableLanguagesIgnoresAFileNameWithATrailingNewline ()
 The regex ends in \z, not $, which in PCRE also matches before a trailing newline; file names may legally contain "\n". More...
 
 testGetLocalLanguagesReturnsEmptyArrayWhenCustomizingDirectoryIsEmpty ()
 
 testGetInstallableLanguagesExtractsKeysFromMainFilesAndIgnoresUnrelatedFiles ()
 
 testCheckLocalLanguageFileReturnsFalseWhenNoLocalFileExists ()
 
 testCheckLocalLanguageFileReturnsTrueForAValidLocalFile ()
 
 testCheckLocalLanguageFileReturnsFalseForAnInvalidLocalFile ()
 
 testCheckLocalLanguageFileReturnsFalseForMalformedLine ()
 
 testCheckLocalLanguageFileReturnsFalseWhenNoCustomizingDirectoryIsConfiguredAtAll ()
 getCustomizingDirectories() always yields one directory in production, so the "zero directories" branch (return false) is reachable only with a mocked manager, which this class otherwise avoids. More...
 
 testCheckLanguageAcceptsAParsableShippedPo ()
 
 testCheckLanguageRejectsAnUnparsableShippedPo (string $po_content)
 Everything gettext/gettext's StrictPoLoader rejects invalidates the language, including what the old parser tolerated (a duplicate, a message without msgstr). More...
 
 testCheckLanguageAcceptsAShippedPoWithBomAndCrLf ()
 A BOM and CRLF line endings are no reason to refuse the language. More...
 
 testCheckLanguageAcceptsAModuleWithoutShippedPoForTheLanguage ()
 
 testCheckLanguageDoesNotParsePoFilesOfTheLocalDirectory ()
 
 testCheckLanguageAcceptsAnEmptyShippedPo ()
 An empty .po is a valid, empty catalog. More...
 
 testCheckShippedLanguageIgnoresAnInvalidCustomizingFileThatMakesCheckLanguageFail ()
 checkShippedLanguage() is checkLanguage() without the customizing directory: an invalid "ilias_de.lang.local" must not block it. More...
 
 testCheckShippedLanguageRejectsAnInvalidGlobalLanguageFile ()
 An invalid global "ilias_de.lang" is part of getDirectories(), so checkShippedLanguage() fails like checkLanguage(). More...
 
 testCheckShippedLanguageRejectsAnUnparsableShippedPo ()
 An unparsable shipped .po of a PO-maintained module is part of getDirectories() too, so checkShippedLanguage() fails like checkLanguage(). More...
 

Static Public Member Functions

static unparsableShippedPo ()
 

Private Member Functions

 createReadDatabaseMock ()
 
 configureDbToReturnObjectRows (Stub &ilDBInterface $db, array $rows)
 The read methods call fetchObject() on the database object, not on the statement, so the rows are stubbed on $db. More...
 
 createStatementReturningAssocRows (array $rows)
 
 createRepository (ilDBInterface $db, string $absolute_path='/does/not/matter/for/db-only/tests')
 
 checkLanguageWithShippedPo (?string $po_content, bool $local_directory=false)
 checkLanguage() for a migrated module: the shipped .po is the only source of its values, so an unparsable one invalidates the language. More...
 
 createTempInstallationRoot ()
 
 removeDirectory (string $dir)
 

Detailed Description

Database-backed methods run against an ilDBInterface mock returning controlled rows; filesystem-backed methods use a real temporary installation root, like LanguageInstallationManagerTest.

Definition at line 34 of file InstalledLanguageDatabaseRepositoryTest.php.

Member Function Documentation

◆ checkLanguageWithShippedPo()

InstalledLanguageDatabaseRepositoryTest::checkLanguageWithShippedPo ( ?string  $po_content,
bool  $local_directory = false 
)
private

checkLanguage() for a migrated module: the shipped .po is the only source of its values, so an unparsable one invalidates the language.

Builds a root with a valid main lang file and a "pilot" component whose shipped de .po has $po_content (null = no .po).

Definition at line 481 of file InstalledLanguageDatabaseRepositoryTest.php.

481 : bool
482 {
483 $root = $this->createTempInstallationRoot();
484 file_put_contents($root . '/lang/ilias_de.lang', "<!-- language file start -->\ncommon#:#yes#:#Ja\n");
485 mkdir($root . '/components/pilot/lang', 0777, true);
486 if ($po_content !== null) {
487 file_put_contents($root . '/components/pilot/lang/pilot_de.po', $po_content);
488 }
489 $pilot = MigratedPoFixture::directory('pilot', 'components/pilot/lang/', $local_directory);
490
491 try {
492 $repository = new InstalledLanguageDatabaseRepository(
493 $this->createReadDatabaseMock(),
494 $local_directory
497 new FixedInstallationRoot($root)
498 );
499 return $repository->checkLanguage('de');
500 } finally {
501 $this->removeDirectory($root);
502 }
503 }
A root determined by the caller, for the classes which are not wired by the component bootstrap.
static directory(string $prefix, string $path, bool $local=false)

References MigratedPoFixture\directory().

+ Here is the call graph for this function:

◆ configureDbToReturnObjectRows()

InstalledLanguageDatabaseRepositoryTest::configureDbToReturnObjectRows ( Stub &ilDBInterface  $db,
array  $rows 
)
private

The read methods call fetchObject() on the database object, not on the statement, so the rows are stubbed on $db.

query() is left to each test, so no two stubs compete.

Parameters
list<array<string,mixed>>$rows each row as an associative array of column => value

Definition at line 56 of file InstalledLanguageDatabaseRepositoryTest.php.

56 : void
57 {
58 $objects = array_map(static fn(array $row): \stdClass => (object) $row, $rows);
59 $objects[] = null; // terminates the while ($row = ...) loop
60 $db->method('fetchObject')->willReturn(...$objects);
61 }

References ILIAS\Scripts\PHPStan\$rows.

◆ createReadDatabaseMock()

InstalledLanguageDatabaseRepositoryTest::createReadDatabaseMock ( )
private

Definition at line 36 of file InstalledLanguageDatabaseRepositoryTest.php.

36 : Stub&ilDBInterface
37 {
38 $db = $this->createStub(ilDBInterface::class);
39 $db->method('quote')->willReturnCallback(
40 static fn(mixed $value, string $type): string => "'" . (string) $value . "'"
41 );
42 $db->method('like')->willReturnCallback(
43 static fn(string $column, string $type, string $value = "?", bool $ci = true): string =>
44 $column . " LIKE " . "'" . $value . "'"
45 );
46
47 return $db;
48 }
Interface ilDBInterface.

◆ createRepository()

InstalledLanguageDatabaseRepositoryTest::createRepository ( ilDBInterface  $db,
string  $absolute_path = '/does/not/matter/for/db-only/tests' 
)
private

◆ createStatementReturningAssocRows()

InstalledLanguageDatabaseRepositoryTest::createStatementReturningAssocRows ( array  $rows)
private
Parameters
list<array<string,mixed>>$rows each row as an associative array of column => value

Definition at line 66 of file InstalledLanguageDatabaseRepositoryTest.php.

66 : Stub&ilDBStatement
67 {
68 $statement = $this->createStub(ilDBStatement::class);
69 $rows[] = null; // terminates the while ($row = ...) loop
70 $statement->method('fetchRow')->willReturn(...$rows);
71
72 return $statement;
73 }
Interface ilDBStatement.

References ILIAS\Scripts\PHPStan\$rows.

◆ createTempInstallationRoot()

InstalledLanguageDatabaseRepositoryTest::createTempInstallationRoot ( )
private

Definition at line 624 of file InstalledLanguageDatabaseRepositoryTest.php.

624 : string
625 {
626 $dir = sys_get_temp_dir() . '/ilias_lang_repo_test_' . bin2hex(random_bytes(8));
627 mkdir($dir . '/lang/customizing', 0777, true);
628 return $dir;
629 }

◆ removeDirectory()

InstalledLanguageDatabaseRepositoryTest::removeDirectory ( string  $dir)
private

Definition at line 631 of file InstalledLanguageDatabaseRepositoryTest.php.

631 : void
632 {
633 if (!is_dir($dir)) {
634 return;
635 }
636 $items = scandir($dir);
637 foreach ($items as $item) {
638 if ($item === '.' || $item === '..') {
639 continue;
640 }
641 $path = $dir . '/' . $item;
642 if (is_dir($path) && !is_link($path)) {
643 $this->removeDirectory($path);
644 } else {
645 unlink($path);
646 }
647 }
648 rmdir($dir);
649 }

◆ testCheckLanguageAcceptsAModuleWithoutShippedPoForTheLanguage()

InstalledLanguageDatabaseRepositoryTest::testCheckLanguageAcceptsAModuleWithoutShippedPoForTheLanguage ( )

Definition at line 544 of file InstalledLanguageDatabaseRepositoryTest.php.

544 : void
545 {
546 $this->assertTrue($this->checkLanguageWithShippedPo(null));
547 }
checkLanguageWithShippedPo(?string $po_content, bool $local_directory=false)
checkLanguage() for a migrated module: the shipped .po is the only source of its values,...

◆ testCheckLanguageAcceptsAnEmptyShippedPo()

InstalledLanguageDatabaseRepositoryTest::testCheckLanguageAcceptsAnEmptyShippedPo ( )

An empty .po is a valid, empty catalog.

Definition at line 557 of file InstalledLanguageDatabaseRepositoryTest.php.

557 : void
558 {
559 $this->assertTrue($this->checkLanguageWithShippedPo(''));
560 }

◆ testCheckLanguageAcceptsAParsableShippedPo()

InstalledLanguageDatabaseRepositoryTest::testCheckLanguageAcceptsAParsableShippedPo ( )

Definition at line 505 of file InstalledLanguageDatabaseRepositoryTest.php.

505 : void
506 {
507 $this->assertTrue($this->checkLanguageWithShippedPo("msgctxt \"pilot\"\nmsgid \"greeting\"\nmsgstr \"Hallo\"\n"));
508 }

◆ testCheckLanguageAcceptsAShippedPoWithBomAndCrLf()

InstalledLanguageDatabaseRepositoryTest::testCheckLanguageAcceptsAShippedPoWithBomAndCrLf ( )

A BOM and CRLF line endings are no reason to refuse the language.

Definition at line 537 of file InstalledLanguageDatabaseRepositoryTest.php.

537 : void
538 {
539 $this->assertTrue($this->checkLanguageWithShippedPo(
540 "\xEF\xBB\xBFmsgid \"\"\r\nmsgstr \"\"\r\n\"Language: de\\n\"\r\n\r\nmsgctxt \"pilot\"\r\nmsgid \"greeting\"\r\nmsgstr \"Hallo\"\r\n"
541 ));
542 }

◆ testCheckLanguageDoesNotParsePoFilesOfTheLocalDirectory()

InstalledLanguageDatabaseRepositoryTest::testCheckLanguageDoesNotParsePoFilesOfTheLocalDirectory ( )

Definition at line 549 of file InstalledLanguageDatabaseRepositoryTest.php.

549 : void
550 {
551 $this->assertTrue($this->checkLanguageWithShippedPo("msgid \"abc\n", true));
552 }

◆ testCheckLanguageRejectsAnUnparsableShippedPo()

InstalledLanguageDatabaseRepositoryTest::testCheckLanguageRejectsAnUnparsableShippedPo ( string  $po_content)

Everything gettext/gettext's StrictPoLoader rejects invalidates the language, including what the old parser tolerated (a duplicate, a message without msgstr).

Definition at line 515 of file InstalledLanguageDatabaseRepositoryTest.php.

515 : void
516 {
517 $this->assertFalse($this->checkLanguageWithShippedPo($po_content));
518 }

◆ testCheckLocalLanguageFileReturnsFalseForAnInvalidLocalFile()

InstalledLanguageDatabaseRepositoryTest::testCheckLocalLanguageFileReturnsFalseForAnInvalidLocalFile ( )

Definition at line 421 of file InstalledLanguageDatabaseRepositoryTest.php.

421 : void
422 {
423 $root = $this->createTempInstallationRoot();
424 file_put_contents(
425 $root . '/lang/customizing/ilias_de.lang.local',
426 "common#:#test#:#Custom Value\n"
427 );
428
429 try {
430 $repository = $this->createRepository($this->createReadDatabaseMock(), $root);
431 $this->assertFalse($repository->checkLocalLanguageFile('de'));
432 } finally {
433 $this->removeDirectory($root);
434 }
435 }
createRepository(ilDBInterface $db, string $absolute_path='/does/not/matter/for/db-only/tests')

◆ testCheckLocalLanguageFileReturnsFalseForMalformedLine()

InstalledLanguageDatabaseRepositoryTest::testCheckLocalLanguageFileReturnsFalseForMalformedLine ( )

Definition at line 437 of file InstalledLanguageDatabaseRepositoryTest.php.

437 : void
438 {
439 $root = $this->createTempInstallationRoot();
440 file_put_contents(
441 $root . '/lang/customizing/ilias_de.lang.local',
442 "<!-- language file start -->\nonly_one_field\n"
443 );
444
445 try {
446 $repository = $this->createRepository($this->createReadDatabaseMock(), $root);
447 $this->assertFalse($repository->checkLocalLanguageFile('de'));
448 } finally {
449 $this->removeDirectory($root);
450 }
451 }

◆ testCheckLocalLanguageFileReturnsFalseWhenNoCustomizingDirectoryIsConfiguredAtAll()

InstalledLanguageDatabaseRepositoryTest::testCheckLocalLanguageFileReturnsFalseWhenNoCustomizingDirectoryIsConfiguredAtAll ( )

getCustomizingDirectories() always yields one directory in production, so the "zero directories" branch (return false) is reachable only with a mocked manager, which this class otherwise avoids.

Definition at line 457 of file InstalledLanguageDatabaseRepositoryTest.php.

457 : void
458 {
459 $manager = $this->createStub(LanguageFileDirectoryManager::class);
460 $manager->method('getCustomizingDirectories')->willReturnCallback(
461 static function (): \Generator {
462 return;
463 yield; // unreachable; makes this a generator that yields nothing
464 }
465 );
466
467 $repository = new InstalledLanguageDatabaseRepository(
468 $this->createReadDatabaseMock(),
469 $manager,
470 new FixedInstallationRoot('/does/not/matter/for/this/test')
471 );
472
473 $this->assertFalse($repository->checkLocalLanguageFile('de'));
474 }

◆ testCheckLocalLanguageFileReturnsFalseWhenNoLocalFileExists()

InstalledLanguageDatabaseRepositoryTest::testCheckLocalLanguageFileReturnsFalseWhenNoLocalFileExists ( )

Definition at line 392 of file InstalledLanguageDatabaseRepositoryTest.php.

392 : void
393 {
394 $root = $this->createTempInstallationRoot();
395
396 try {
397 $repository = $this->createRepository($this->createReadDatabaseMock(), $root);
398 // unlike checkLanguage(), a missing local file is not acceptable here
399 $this->assertFalse($repository->checkLocalLanguageFile('de'));
400 } finally {
401 $this->removeDirectory($root);
402 }
403 }

◆ testCheckLocalLanguageFileReturnsTrueForAValidLocalFile()

InstalledLanguageDatabaseRepositoryTest::testCheckLocalLanguageFileReturnsTrueForAValidLocalFile ( )

Definition at line 405 of file InstalledLanguageDatabaseRepositoryTest.php.

405 : void
406 {
407 $root = $this->createTempInstallationRoot();
408 file_put_contents(
409 $root . '/lang/customizing/ilias_de.lang.local',
410 "<!-- language file start -->\ncommon#:#test#:#Custom Value\n"
411 );
412
413 try {
414 $repository = $this->createRepository($this->createReadDatabaseMock(), $root);
415 $this->assertTrue($repository->checkLocalLanguageFile('de'));
416 } finally {
417 $this->removeDirectory($root);
418 }
419 }

◆ testCheckShippedLanguageIgnoresAnInvalidCustomizingFileThatMakesCheckLanguageFail()

InstalledLanguageDatabaseRepositoryTest::testCheckShippedLanguageIgnoresAnInvalidCustomizingFileThatMakesCheckLanguageFail ( )

checkShippedLanguage() is checkLanguage() without the customizing directory: an invalid "ilias_de.lang.local" must not block it.

Definition at line 566 of file InstalledLanguageDatabaseRepositoryTest.php.

566 : void
567 {
568 $root = $this->createTempInstallationRoot();
569 file_put_contents($root . '/lang/ilias_de.lang', "<!-- language file start -->\ncommon#:#yes#:#Ja\n");
570 file_put_contents($root . '/lang/customizing/ilias_de.lang.local', "<!-- language file start -->\nonly_one_field\n");
571
572 try {
573 $repository = $this->createRepository($this->createReadDatabaseMock(), $root);
574
575 $this->assertTrue($repository->checkShippedLanguage('de'), 'the invalid customizing file is never consulted');
576 $this->assertFalse($repository->checkLanguage('de'), 'precondition: the same file makes checkLanguage() fail');
577 } finally {
578 $this->removeDirectory($root);
579 }
580 }

◆ testCheckShippedLanguageRejectsAnInvalidGlobalLanguageFile()

InstalledLanguageDatabaseRepositoryTest::testCheckShippedLanguageRejectsAnInvalidGlobalLanguageFile ( )

An invalid global "ilias_de.lang" is part of getDirectories(), so checkShippedLanguage() fails like checkLanguage().

Definition at line 585 of file InstalledLanguageDatabaseRepositoryTest.php.

585 : void
586 {
587 $root = $this->createTempInstallationRoot();
588 file_put_contents($root . '/lang/ilias_de.lang', "common#:#yes#:#Ja\n");
589
590 try {
591 $repository = $this->createRepository($this->createReadDatabaseMock(), $root);
592
593 $this->assertFalse($repository->checkShippedLanguage('de'));
594 } finally {
595 $this->removeDirectory($root);
596 }
597 }

◆ testCheckShippedLanguageRejectsAnUnparsableShippedPo()

InstalledLanguageDatabaseRepositoryTest::testCheckShippedLanguageRejectsAnUnparsableShippedPo ( )

An unparsable shipped .po of a PO-maintained module is part of getDirectories() too, so checkShippedLanguage() fails like checkLanguage().

Definition at line 603 of file InstalledLanguageDatabaseRepositoryTest.php.

603 : void
604 {
605 $root = $this->createTempInstallationRoot();
606 file_put_contents($root . '/lang/ilias_de.lang', "<!-- language file start -->\ncommon#:#yes#:#Ja\n");
607 mkdir($root . '/components/pilot/lang', 0777, true);
608 file_put_contents($root . '/components/pilot/lang/pilot_de.po', "msgctxt \"pilot\"\nmsgid \"abc\nmsgstr \"Hallo\"\n");
609 $pilot = MigratedPoFixture::directory('pilot', 'components/pilot/lang/');
610
611 try {
612 $repository = new InstalledLanguageDatabaseRepository(
613 $this->createReadDatabaseMock(),
615 new FixedInstallationRoot($root)
616 );
617
618 $this->assertFalse($repository->checkShippedLanguage('de'));
619 } finally {
620 $this->removeDirectory($root);
621 }
622 }

References MigratedPoFixture\directory().

+ Here is the call graph for this function:

◆ testGetAvailableLanguagesMapsObjIdAndStatusToTheCorrectLanguageNotSwapped()

InstalledLanguageDatabaseRepositoryTest::testGetAvailableLanguagesMapsObjIdAndStatusToTheCorrectLanguageNotSwapped ( )

Definition at line 86 of file InstalledLanguageDatabaseRepositoryTest.php.

86 : void
87 {
88 $db = $this->createReadDatabaseMock();
89 $db->method('query')->willReturn($this->createStub(ilDBStatement::class));
91 ['title' => 'de', 'description' => 'installed', 'obj_id' => 5],
92 ['title' => 'en', 'description' => 'not_installed', 'obj_id' => 8],
93 ]);
94
95 $result = $this->createRepository($db)->getAvailableLanguages();
96
97 $this->assertSame(
98 [
99 'de' => ['obj_id' => 5, 'status' => 'installed'],
100 'en' => ['obj_id' => 8, 'status' => 'not_installed'],
101 ],
102 $result
103 );
104 }
configureDbToReturnObjectRows(Stub &ilDBInterface $db, array $rows)
The read methods call fetchObject() on the database object, not on the statement, so the rows are stu...

◆ testGetAvailableLanguagesReturnsEmptyArrayWhenNoLanguagesAreKnown()

InstalledLanguageDatabaseRepositoryTest::testGetAvailableLanguagesReturnsEmptyArrayWhenNoLanguagesAreKnown ( )

Definition at line 106 of file InstalledLanguageDatabaseRepositoryTest.php.

106 : void
107 {
108 $db = $this->createReadDatabaseMock();
109 $db->method('query')->willReturn($this->createStub(ilDBStatement::class));
110 $this->configureDbToReturnObjectRows($db, []);
111
112 $this->assertSame([], $this->createRepository($db)->getAvailableLanguages());
113 }

◆ testGetInstallableLanguagesExtractsKeysFromMainFilesAndIgnoresUnrelatedFiles()

InstalledLanguageDatabaseRepositoryTest::testGetInstallableLanguagesExtractsKeysFromMainFilesAndIgnoresUnrelatedFiles ( )

Definition at line 371 of file InstalledLanguageDatabaseRepositoryTest.php.

371 : void
372 {
373 $root = $this->createTempInstallationRoot();
374 file_put_contents($root . '/lang/ilias_de.lang', 'irrelevant content');
375 file_put_contents($root . '/lang/ilias_en.lang', 'irrelevant content');
376 // a local file is not installable, nor is a name outside the "ilias_xx.lang" scheme
377 file_put_contents($root . '/lang/ilias_fr.lang.local', 'irrelevant content');
378 file_put_contents($root . '/lang/notes.txt', 'irrelevant content');
379
380 try {
381 $repository = $this->createRepository($this->createReadDatabaseMock(), $root);
382
383 $result = $repository->getInstallableLanguages();
384
385 sort($result);
386 $this->assertSame(['de', 'en'], $result);
387 } finally {
388 $this->removeDirectory($root);
389 }
390 }

References ILIAS\UI\examples\Symbol\Glyph\Sort\sort().

+ Here is the call graph for this function:

◆ testGetInstallableLanguagesIgnoresAFileNameWithATrailingNewline()

InstalledLanguageDatabaseRepositoryTest::testGetInstallableLanguagesIgnoresAFileNameWithATrailingNewline ( )

The regex ends in \z, not $, which in PCRE also matches before a trailing newline; file names may legally contain "\n".

Definition at line 341 of file InstalledLanguageDatabaseRepositoryTest.php.

341 : void
342 {
343 $root = $this->createTempInstallationRoot();
344 file_put_contents($root . '/lang/ilias_de.lang', 'irrelevant content');
345 // distinct key "zz": a wrongly accepted trailing "\n" would show up as an extra entry, not collapse into "de"
346 file_put_contents($root . "/lang/ilias_zz.lang\n", 'irrelevant content');
347
348 try {
349 $repository = $this->createRepository($this->createReadDatabaseMock(), $root);
350
351 $result = $repository->getInstallableLanguages();
352
353 $this->assertSame(['de'], $result);
354 } finally {
355 $this->removeDirectory($root);
356 }
357 }

◆ testGetInstallableLanguagesIgnoresFilesWithAnInvalidLanguageKeyShapeInTheirName()

InstalledLanguageDatabaseRepositoryTest::testGetInstallableLanguagesIgnoresFilesWithAnInvalidLanguageKeyShapeInTheirName ( )

Same for getInstallableLanguages() (lang/) instead of getLocalLanguages() (lang/customizing/).

Definition at line 319 of file InstalledLanguageDatabaseRepositoryTest.php.

319 : void
320 {
321 $root = $this->createTempInstallationRoot();
322 file_put_contents($root . '/lang/ilias_de.lang', 'irrelevant content');
323 file_put_contents($root . '/lang/ilias_DE.lang', 'irrelevant content');
324 file_put_contents($root . '/lang/ilias_12.lang', 'irrelevant content');
325
326 try {
327 $repository = $this->createRepository($this->createReadDatabaseMock(), $root);
328
329 $result = $repository->getInstallableLanguages();
330
331 $this->assertSame(['de'], $result);
332 } finally {
333 $this->removeDirectory($root);
334 }
335 }

◆ testGetInstalledLanguagesQueriesForInstalledPrefixAndReturnsTitles()

InstalledLanguageDatabaseRepositoryTest::testGetInstalledLanguagesQueriesForInstalledPrefixAndReturnsTitles ( )

Definition at line 115 of file InstalledLanguageDatabaseRepositoryTest.php.

115 : void
116 {
117 $db = $this->createReadDatabaseMock();
118 $captured_query = null;
119 $db->method('query')->willReturnCallback(
120 function (string $query) use (&$captured_query): ilDBStatement {
121 $captured_query = $query;
122 return $this->createStub(ilDBStatement::class);
123 }
124 );
126 ['title' => 'de'],
127 ['title' => 'en'],
128 ]);
129
130 $result = $this->createRepository($db)->getInstalledLanguages();
131
132 $this->assertSame(['de', 'en'], $result);
133 $this->assertStringContainsString("type = 'lng'", $captured_query);
134 $this->assertStringContainsString("description LIKE 'installed%'", $captured_query);
135 }

◆ testGetInstalledLocalLanguagesQueriesForExactlyInstalledLocalAndReturnsTitles()

InstalledLanguageDatabaseRepositoryTest::testGetInstalledLocalLanguagesQueriesForExactlyInstalledLocalAndReturnsTitles ( )

Definition at line 137 of file InstalledLanguageDatabaseRepositoryTest.php.

137 : void
138 {
139 $db = $this->createReadDatabaseMock();
140 $captured_query = null;
141 $db->method('query')->willReturnCallback(
142 function (string $query) use (&$captured_query): ilDBStatement {
143 $captured_query = $query;
144 return $this->createStub(ilDBStatement::class);
145 }
146 );
148 ['title' => 'de'],
149 ]);
150
151 $result = $this->createRepository($db)->getInstalledLocalLanguages();
152
153 $this->assertSame(['de'], $result);
154 $this->assertStringContainsString("description = 'installed_local'", $captured_query);
155 }

◆ testGetLanguageEntriesQueryDoesNotFilterByLocalChange()

InstalledLanguageDatabaseRepositoryTest::testGetLanguageEntriesQueryDoesNotFilterByLocalChange ( )

Unlike getLocalChanges(), getLanguageEntries() returns every stored entry of the language key, so its query must not filter on local_change.

Definition at line 253 of file InstalledLanguageDatabaseRepositoryTest.php.

253 : void
254 {
255 $db = $this->createReadDatabaseMock();
256 $captured_query = null;
257 $db->method('query')->willReturnCallback(
258 function (string $query) use (&$captured_query): ilDBStatement {
259 $captured_query = $query;
260 return $this->createStatementReturningAssocRows([]);
261 }
262 );
263
264 $this->createRepository($db)->getLanguageEntries('de');
265
266 $this->assertStringContainsString("lang_key = 'de'", $captured_query);
267 $this->assertStringNotContainsString('local_change', $captured_query);
268 }

◆ testGetLanguageEntriesReturnsEmptyArrayWhenNothingMatches()

InstalledLanguageDatabaseRepositoryTest::testGetLanguageEntriesReturnsEmptyArrayWhenNothingMatches ( )

Definition at line 241 of file InstalledLanguageDatabaseRepositoryTest.php.

241 : void
242 {
243 $db = $this->createReadDatabaseMock();
244 $db->method('query')->willReturn($this->createStatementReturningAssocRows([]));
245
246 $this->assertSame([], $this->createRepository($db)->getLanguageEntries('de'));
247 }

◆ testGetLanguageEntriesStructuresResultAsModuleThenIdentifierThenValue()

InstalledLanguageDatabaseRepositoryTest::testGetLanguageEntriesStructuresResultAsModuleThenIdentifierThenValue ( )

Definition at line 221 of file InstalledLanguageDatabaseRepositoryTest.php.

221 : void
222 {
223 $db = $this->createReadDatabaseMock();
224 $db->method('query')->willReturn($this->createStatementReturningAssocRows([
225 ['module' => 'common', 'identifier' => 'foo', 'value' => 'Foo Value'],
226 ['module' => 'common', 'identifier' => 'bar', 'value' => 'Bar Value'],
227 ['module' => 'other', 'identifier' => 'baz', 'value' => 'Baz Value'],
228 ]));
229
230 $result = $this->createRepository($db)->getLanguageEntries('de');
231
232 $this->assertSame(
233 [
234 'common' => ['foo' => 'Foo Value', 'bar' => 'Bar Value'],
235 'other' => ['baz' => 'Baz Value'],
236 ],
237 $result
238 );
239 }

◆ testGetLocalChangesDefaultsMinAndMaxDateWhenEmptyStringsArePassed()

InstalledLanguageDatabaseRepositoryTest::testGetLocalChangesDefaultsMinAndMaxDateWhenEmptyStringsArePassed ( )

Definition at line 157 of file InstalledLanguageDatabaseRepositoryTest.php.

157 : void
158 {
159 $db = $this->createReadDatabaseMock();
160 $captured_query = null;
161 $db->method('query')->willReturnCallback(
162 function (string $query) use (&$captured_query): ilDBStatement {
163 $captured_query = $query;
164 return $this->createStatementReturningAssocRows([]);
165 }
166 );
167
168 $this->createRepository($db)->getLocalChanges('de', '', '');
169
170 $this->assertStringContainsString("'1980-01-01 00:00:00'", $captured_query);
171 $this->assertStringContainsString("'2200-01-01 00:00:00'", $captured_query);
172 }

◆ testGetLocalChangesKeepsExplicitlyGivenDatesInsteadOfDefaulting()

InstalledLanguageDatabaseRepositoryTest::testGetLocalChangesKeepsExplicitlyGivenDatesInsteadOfDefaulting ( )

Definition at line 174 of file InstalledLanguageDatabaseRepositoryTest.php.

174 : void
175 {
176 $db = $this->createReadDatabaseMock();
177 $captured_query = null;
178 $db->method('query')->willReturnCallback(
179 function (string $query) use (&$captured_query): ilDBStatement {
180 $captured_query = $query;
181 return $this->createStatementReturningAssocRows([]);
182 }
183 );
184
185 $this->createRepository($db)->getLocalChanges('de', '2020-01-01 00:00:00', '2021-01-01 00:00:00');
186
187 $this->assertStringContainsString("'2020-01-01 00:00:00'", $captured_query);
188 $this->assertStringContainsString("'2021-01-01 00:00:00'", $captured_query);
189 $this->assertStringNotContainsString('1980-01-01', $captured_query);
190 $this->assertStringNotContainsString('2200-01-01', $captured_query);
191 }

◆ testGetLocalChangesReturnsEmptyArrayWhenNothingMatches()

InstalledLanguageDatabaseRepositoryTest::testGetLocalChangesReturnsEmptyArrayWhenNothingMatches ( )

Definition at line 213 of file InstalledLanguageDatabaseRepositoryTest.php.

213 : void
214 {
215 $db = $this->createReadDatabaseMock();
216 $db->method('query')->willReturn($this->createStatementReturningAssocRows([]));
217
218 $this->assertSame([], $this->createRepository($db)->getLocalChanges('de'));
219 }

◆ testGetLocalChangesStructuresResultAsModuleThenIdentifierThenValue()

InstalledLanguageDatabaseRepositoryTest::testGetLocalChangesStructuresResultAsModuleThenIdentifierThenValue ( )

Definition at line 193 of file InstalledLanguageDatabaseRepositoryTest.php.

193 : void
194 {
195 $db = $this->createReadDatabaseMock();
196 $db->method('query')->willReturn($this->createStatementReturningAssocRows([
197 ['module' => 'common', 'identifier' => 'foo', 'value' => 'Foo Value'],
198 ['module' => 'common', 'identifier' => 'bar', 'value' => 'Bar Value'],
199 ['module' => 'other', 'identifier' => 'baz', 'value' => 'Baz Value'],
200 ]));
201
202 $result = $this->createRepository($db)->getLocalChanges('de');
203
204 $this->assertSame(
205 [
206 'common' => ['foo' => 'Foo Value', 'bar' => 'Bar Value'],
207 'other' => ['baz' => 'Baz Value'],
208 ],
209 $result
210 );
211 }

◆ testGetLocalLanguagesExtractsKeysFromLocalFilesAndIgnoresUnrelatedFiles()

InstalledLanguageDatabaseRepositoryTest::testGetLocalLanguagesExtractsKeysFromLocalFilesAndIgnoresUnrelatedFiles ( )

Definition at line 270 of file InstalledLanguageDatabaseRepositoryTest.php.

270 : void
271 {
272 $root = $this->createTempInstallationRoot();
273 file_put_contents($root . '/lang/customizing/ilias_de.lang.local', 'irrelevant content');
274 file_put_contents($root . '/lang/customizing/ilias_en.lang.local', 'irrelevant content');
275 // wrong naming scheme (missing .local suffix, a typo): ignored
276 file_put_contents($root . '/lang/customizing/ilias_fr.lang', 'irrelevant content');
277 file_put_contents($root . '/lang/customizing/README.md', 'irrelevant content');
278
279 try {
280 $repository = $this->createRepository($this->createReadDatabaseMock(), $root);
281
282 $result = $repository->getLocalLanguages();
283
284 sort($result);
285 $this->assertSame(['de', 'en'], $result);
286 $this->assertSame(array_values(array_unique($result)), array_values($result));
287 } finally {
288 $this->removeDirectory($root);
289 }
290 }

References ILIAS\UI\examples\Symbol\Glyph\Sort\sort().

+ Here is the call graph for this function:

◆ testGetLocalLanguagesIgnoresFilesWithAnInvalidLanguageKeyShapeInTheirName()

InstalledLanguageDatabaseRepositoryTest::testGetLocalLanguagesIgnoresFilesWithAnInvalidLanguageKeyShapeInTheirName ( )

The discovery regex must accept exactly ParsesLanguageKeyList::LANGUAGE_KEY_FORMAT ('/^[a-z]{2}$/'): other file names must be ignored, or they would fail later in the Activity's stricter validation.

Definition at line 296 of file InstalledLanguageDatabaseRepositoryTest.php.

296 : void
297 {
298 $root = $this->createTempInstallationRoot();
299 file_put_contents($root . '/lang/customizing/ilias_de.lang.local', 'irrelevant content');
300 file_put_contents($root . '/lang/customizing/ilias_DE.lang.local', 'irrelevant content');
301 file_put_contents($root . '/lang/customizing/ilias_12.lang.local', 'irrelevant content');
302 file_put_contents($root . '/lang/customizing/ilias_Fr.lang.local', 'irrelevant content');
303 file_put_contents($root . '/lang/customizing/ilias_deu.lang.local', 'irrelevant content');
304
305 try {
306 $repository = $this->createRepository($this->createReadDatabaseMock(), $root);
307
308 $result = $repository->getLocalLanguages();
309
310 $this->assertSame(['de'], $result);
311 } finally {
312 $this->removeDirectory($root);
313 }
314 }

◆ testGetLocalLanguagesReturnsEmptyArrayWhenCustomizingDirectoryIsEmpty()

InstalledLanguageDatabaseRepositoryTest::testGetLocalLanguagesReturnsEmptyArrayWhenCustomizingDirectoryIsEmpty ( )

Definition at line 359 of file InstalledLanguageDatabaseRepositoryTest.php.

359 : void
360 {
361 $root = $this->createTempInstallationRoot();
362
363 try {
364 $repository = $this->createRepository($this->createReadDatabaseMock(), $root);
365 $this->assertSame([], $repository->getLocalLanguages());
366 } finally {
367 $this->removeDirectory($root);
368 }
369 }

◆ unparsableShippedPo()

static InstalledLanguageDatabaseRepositoryTest::unparsableShippedPo ( )
static

Definition at line 520 of file InstalledLanguageDatabaseRepositoryTest.php.

520 : array
521 {
522 $message = "msgctxt \"pilot\"\nmsgid \"greeting\"\nmsgstr \"Hallo\"\n";
523
524 return [
525 'unterminated string' => ["msgctxt \"pilot\"\nmsgid \"abc\nmsgstr \"Hallo\"\n"],
526 'duplicate message' => [$message . "\n" . $message],
527 'message without msgstr' => ["msgctxt \"pilot\"\nmsgid \"greeting\"\n"],
528 'truncated inside a string' => [substr($message, 0, -4)],
529 'binary data' => ["\xde\x12\x04\x95\x00\x00\x00\x00"],
530 'header value with a line break' => ["msgid \"\"\nmsgstr \"\"\n\"X-A: a\\rb\\n\"\n\n" . $message],
531 ];
532 }

References $message.


The documentation for this class was generated from the following file: