ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ComponentLanguageFileDirectoryTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use PHPUnit\Framework\TestCase;
25
31{
33 {
34 // a real (non-mock) class defined here, so ReflectionClass::getFileName() resolves to this file - deterministic
35 // and computable below without ComponentLanguageFileDirectory's internals
36 $component = new class () implements Component {
37 public function init(
38 array|\ArrayAccess &$define,
39 array|\ArrayAccess &$implement,
40 array|\ArrayAccess &$use,
41 array|\ArrayAccess &$contribute,
42 array|\ArrayAccess &$seek,
43 array|\ArrayAccess &$provide,
44 array|\ArrayAccess &$pull,
45 array|\ArrayAccess &$internal,
46 ): void {
47 }
48 };
49
50 $directory = new ComponentLanguageFileDirectory($component, 'tst', 'lang/');
51
52 // independently reproduces getPath()'s computation from __DIR__ of this file
53 $ilias_root = (string) realpath(__DIR__ . '/../../../../../');
54 self::assertNotSame('', $ilias_root, 'Could not resolve the ILIAS root from this test file - did it move?');
55 $expected_base_directory = str_replace($ilias_root . '/', '', __DIR__);
56 $expected_path = $expected_base_directory . '/lang/';
57
58 $first_call = $directory->getPath();
59 $second_call = $directory->getPath();
60 $third_call = $directory->getPath();
61
62 self::assertSame($expected_path, $first_call);
63 self::assertSame($first_call, $second_call);
64 self::assertSame($first_call, $third_call);
65 }
66
68 {
69 $component = new class () implements Component {
70 public function init(
71 array|\ArrayAccess &$define,
72 array|\ArrayAccess &$implement,
73 array|\ArrayAccess &$use,
74 array|\ArrayAccess &$contribute,
75 array|\ArrayAccess &$seek,
76 array|\ArrayAccess &$provide,
77 array|\ArrayAccess &$pull,
78 array|\ArrayAccess &$internal,
79 ): void {
80 }
81 };
82
83 $directory = new ComponentLanguageFileDirectory($component, 'tst', 'custom/lang/path/');
84
85 self::assertStringEndsWith('/custom/lang/path/', $directory->getPath());
86 }
87
88 private function anyComponent(): Component
89 {
90 return new class () implements Component {
91 public function init(
92 array|\ArrayAccess &$define,
93 array|\ArrayAccess &$implement,
94 array|\ArrayAccess &$use,
95 array|\ArrayAccess &$contribute,
96 array|\ArrayAccess &$seek,
97 array|\ArrayAccess &$provide,
98 array|\ArrayAccess &$pull,
99 array|\ArrayAccess &$internal,
100 ): void {
101 }
102 };
103 }
104
106 {
107 $directory = new ComponentLanguageFileDirectory($this->anyComponent(), 'tos');
108
109 self::assertSame('tos_%s', $directory->getShippedFileNamePattern());
110 }
111
113 {
114 $directory = new ComponentLanguageFileDirectory($this->anyComponent(), 'tos', 'lang/', 'ilias_%s');
115
116 self::assertSame('ilias_%s', $directory->getShippedFileNamePattern());
117 }
118
120 {
121 $this->expectException(\InvalidArgumentException::class);
122
123 new ComponentLanguageFileDirectory($this->anyComponent(), 'tos', 'lang/', 'no-placeholder-at-all');
124 }
125}
Non-regression guard for the base directory getPath() caches: repeated calls on an unchanged object r...
init(array|\ArrayAccess &$define, array|\ArrayAccess &$implement, array|\ArrayAccess &$use, array|\ArrayAccess &$contribute, array|\ArrayAccess &$seek, array|\ArrayAccess &$provide, array|\ArrayAccess &$pull, array|\ArrayAccess &$internal,)
Definition: Language.php:44
$ilias_root
Lists every identifier of the shipped lang/ilias_*.lang files that occurs in one module in spellings ...