ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\Language\Tests\Activities\UninstallLanguageAmbiguityTest Class Reference
+ Inheritance diagram for ILIAS\Language\Tests\Activities\UninstallLanguageAmbiguityTest:
+ Collaboration diagram for ILIAS\Language\Tests\Activities\UninstallLanguageAmbiguityTest:

Public Member Functions

 testAmbiguousTitleRejectsTheRequestAndNeverCallsTheObjectFactoryForIt ()
 
 testAmbiguousTitleExceptionMessageContainsTheRawUnescapedTitle ()
 The exception message embeds the ambiguous title unescaped: escaping is RendersActivityErrors::activityErrorMessage()'s job. More...
 
 testAmbiguousTitleViaMaybePerformAsReturnsResultErrorAndNeverCallsTheObjectFactory ()
 Via maybePerformAs() the exception must surface as a Result\Error, and the object factory stays untouched. More...
 
 testUnambiguousLanguageKeyStillWorksAlongsideAnAmbiguousOneInTheSameLngObjectsList ()
 An ambiguous title must not affect a unique language key in the same request. More...
 
 testAnUnambiguousKeyBeforeAnAmbiguousOneIsNeverUninstalledOnceTheWholeRequestIsRejected ()
 The ambiguity check runs for all requested keys before any uninstall() call. More...
 
 testMaybePerformAsNeverUninstallsAnUnambiguousKeyWhenAnotherRequestedKeyIsAmbiguous ()
 Same, end-to-end through maybePerformAs(). More...
 

Additional Inherited Members

- Protected Member Functions inherited from ilLanguageBaseTestCase
 setUp ()
 
 setGlobalVariable (string $name, $value)
 
 rbacOf (\ilRbacSystem $system)
 
 languageFolder (int $ref_id=0)
 

Detailed Description

Definition at line 28 of file UninstallLanguageAmbiguityTest.php.

Member Function Documentation

◆ testAmbiguousTitleExceptionMessageContainsTheRawUnescapedTitle()

ILIAS\Language\Tests\Activities\UninstallLanguageAmbiguityTest::testAmbiguousTitleExceptionMessageContainsTheRawUnescapedTitle ( )

The exception message embeds the ambiguous title unescaped: escaping is RendersActivityErrors::activityErrorMessage()'s job.

Definition at line 61 of file UninstallLanguageAmbiguityTest.php.

61 : void
62 {
63 $ambiguous_title = 'de';
64 $lng_objects = static fn(): array => [
65 ['obj_id' => 1, 'title' => $ambiguous_title],
66 ['obj_id' => 2, 'title' => $ambiguous_title],
67 ];
68 $obj_language_factory = static function (int $id): never {
69 throw new \LogicException('must never be called for an ambiguous title');
70 };
71
72 $activity = $this->createActivity($lng_objects, $obj_language_factory);
73
74 try {
75 $activity->perform(['language_keys' => $ambiguous_title]);
76 $this->fail('Expected an AmbiguousLanguageTitleException to be thrown.');
77 } catch (AmbiguousLanguageTitleException $e) {
78 $this->assertStringContainsString($ambiguous_title, $e->getMessage());
79 $this->assertStringNotContainsString('<script>', $e->getMessage());
80 $this->assertStringNotContainsString('"', $e->getMessage());
81 }
82 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
createActivity(\Closure $lng_objects, \Closure $obj_language_factory, ?\ilRbacSystem $rbac=null, int $language_folder_ref_id=0, ?RepositoryProvider $repository=null,)

References Vendor\Package\$e, $id, and ILIAS\Language\Tests\Activities\createActivity().

+ Here is the call graph for this function:

◆ testAmbiguousTitleRejectsTheRequestAndNeverCallsTheObjectFactoryForIt()

ILIAS\Language\Tests\Activities\UninstallLanguageAmbiguityTest::testAmbiguousTitleRejectsTheRequestAndNeverCallsTheObjectFactoryForIt ( )

Definition at line 33 of file UninstallLanguageAmbiguityTest.php.

33 : void
34 {
35 $lng_objects = static fn(): array => [
36 ['obj_id' => 1, 'title' => 'de'],
37 ['obj_id' => 2, 'title' => 'de'],
38 ];
39 $factory_calls = [];
40 $obj_language_factory = static function (int $id) use (&$factory_calls): never {
41 $factory_calls[] = $id;
42 throw new \LogicException('must never be called for an ambiguous title');
43 };
44
45 $activity = $this->createActivity($lng_objects, $obj_language_factory);
46
47 $this->expectException(\RuntimeException::class);
48 $this->expectExceptionMessageMatches('/"de"/');
49
50 try {
51 $activity->perform(['language_keys' => 'de']);
52 } finally {
53 $this->assertSame([], $factory_calls);
54 }
55 }

References $id, and ILIAS\Language\Tests\Activities\createActivity().

+ Here is the call graph for this function:

◆ testAmbiguousTitleViaMaybePerformAsReturnsResultErrorAndNeverCallsTheObjectFactory()

ILIAS\Language\Tests\Activities\UninstallLanguageAmbiguityTest::testAmbiguousTitleViaMaybePerformAsReturnsResultErrorAndNeverCallsTheObjectFactory ( )

Via maybePerformAs() the exception must surface as a Result\Error, and the object factory stays untouched.

Definition at line 87 of file UninstallLanguageAmbiguityTest.php.

87 : void
88 {
89 $rbac = $this->createStub(\ilRbacSystem::class);
90 $rbac->method('checkAccessOfUser')->willReturn(true);
91
92 $lng_objects = static fn(): array => [
93 ['obj_id' => 1, 'title' => 'de'],
94 ['obj_id' => 2, 'title' => 'de'],
95 ];
96 $factory_calls = [];
97 $obj_language_factory = static function (int $id) use (&$factory_calls): never {
98 $factory_calls[] = $id;
99 throw new \LogicException('must never be called for an ambiguous title');
100 };
101
102 $result = $this->createActivity($lng_objects, $obj_language_factory, $rbac)
103 ->maybePerformAs($this->createRealFieldsUiFactory()->input(), 6, ['language_keys' => 'de']);
104
105 $this->assertTrue($result->isError());
106 $this->assertInstanceOf(\RuntimeException::class, $result->error());
107 $this->assertSame([], $factory_calls);
108 }

References $id, and ILIAS\Language\Tests\Activities\createActivity().

+ Here is the call graph for this function:

◆ testAnUnambiguousKeyBeforeAnAmbiguousOneIsNeverUninstalledOnceTheWholeRequestIsRejected()

ILIAS\Language\Tests\Activities\UninstallLanguageAmbiguityTest::testAnUnambiguousKeyBeforeAnAmbiguousOneIsNeverUninstalledOnceTheWholeRequestIsRejected ( )

The ambiguity check runs for all requested keys before any uninstall() call.

Definition at line 140 of file UninstallLanguageAmbiguityTest.php.

140 : void
141 {
142 $de = new FakeLanguageObject(is_system_language: false, is_user_language: false, is_installed: true);
143
144 $lng_objects = static fn(): array => [
145 ['obj_id' => 1, 'title' => 'de'],
146 ['obj_id' => 2, 'title' => 'fr'],
147 ['obj_id' => 3, 'title' => 'fr'],
148 ];
149 $factory_calls = [];
150 $obj_language_factory = static function (int $id) use (&$factory_calls, $de): FakeLanguageObject {
151 $factory_calls[] = $id;
152 if ($id === 1) {
153 return $de;
154 }
155
156 throw new \LogicException('must never be called for the ambiguous "fr" title');
157 };
158
159 $activity = $this->createActivity($lng_objects, $obj_language_factory);
160
161 try {
162 // 'de' is listed before the ambiguous 'fr' on purpose: an inline check would uninstall 'de' first
163 $activity->perform(['language_keys' => 'de,fr']);
164 $this->fail('Expected an AmbiguousLanguageTitleException to be thrown.');
165 } catch (AmbiguousLanguageTitleException $e) {
166 $this->assertStringContainsString('"fr"', $e->getMessage());
167 // 'de' was never resolved, let alone uninstalled
168 $this->assertSame([], $factory_calls);
169 $this->assertSame(0, $de->uninstallCallCount());
170 }
171 }

References Vendor\Package\$e, $id, and ILIAS\Language\Tests\Activities\createActivity().

+ Here is the call graph for this function:

◆ testMaybePerformAsNeverUninstallsAnUnambiguousKeyWhenAnotherRequestedKeyIsAmbiguous()

ILIAS\Language\Tests\Activities\UninstallLanguageAmbiguityTest::testMaybePerformAsNeverUninstallsAnUnambiguousKeyWhenAnotherRequestedKeyIsAmbiguous ( )

Same, end-to-end through maybePerformAs().

Definition at line 176 of file UninstallLanguageAmbiguityTest.php.

176 : void
177 {
178 $rbac = $this->createStub(\ilRbacSystem::class);
179 $rbac->method('checkAccessOfUser')->willReturn(true);
180
181 $de = new FakeLanguageObject(is_system_language: false, is_user_language: false, is_installed: true);
182
183 $lng_objects = static fn(): array => [
184 ['obj_id' => 1, 'title' => 'de'],
185 ['obj_id' => 2, 'title' => 'fr'],
186 ['obj_id' => 3, 'title' => 'fr'],
187 ];
188 $obj_language_factory = static function (int $id) use ($de): FakeLanguageObject {
189 if ($id === 1) {
190 return $de;
191 }
192
193 throw new \LogicException('must never be called for the ambiguous "fr" title');
194 };
195
196 $result = $this->createActivity($lng_objects, $obj_language_factory, $rbac)
197 ->maybePerformAs($this->createRealFieldsUiFactory()->input(), 6, ['language_keys' => ['de', 'fr']]);
198
199 $this->assertTrue($result->isError());
200 $this->assertInstanceOf(AmbiguousLanguageTitleException::class, $result->error());
201 $this->assertSame(0, $de->uninstallCallCount());
202 }

References $id, and ILIAS\Language\Tests\Activities\createActivity().

+ Here is the call graph for this function:

◆ testUnambiguousLanguageKeyStillWorksAlongsideAnAmbiguousOneInTheSameLngObjectsList()

ILIAS\Language\Tests\Activities\UninstallLanguageAmbiguityTest::testUnambiguousLanguageKeyStillWorksAlongsideAnAmbiguousOneInTheSameLngObjectsList ( )

An ambiguous title must not affect a unique language key in the same request.

Definition at line 113 of file UninstallLanguageAmbiguityTest.php.

113 : void
114 {
115 $lng_objects = static fn(): array => [
116 ['obj_id' => 1, 'title' => 'de'],
117 ['obj_id' => 2, 'title' => 'de'],
118 ['obj_id' => 3, 'title' => 'fr'],
119 ];
120 $fr = new FakeLanguageObject(is_system_language: false, is_user_language: false, is_installed: true);
121 $obj_language_factory = static function (int $id) use ($fr): FakeLanguageObject {
122 if ($id === 3) {
123 return $fr;
124 }
125
126 throw new \LogicException('must never be called for the ambiguous "de" title');
127 };
128
129 $activity = $this->createActivity($lng_objects, $obj_language_factory);
130
131 $result = $activity->perform(['language_keys' => 'fr']);
132
133 $this->assertSame(['fr'], $result['uninstalled_language_keys']);
134 $this->assertSame(1, $fr->uninstallCallCount());
135 }

References $id, and ILIAS\Language\Tests\Activities\createActivity().

+ Here is the call graph for this function:

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