19declare(strict_types=1);
30 use RealFieldsUiFactory;
35 $lng_objects =
static fn(): array => [
36 [
'obj_id' => 1,
'title' =>
'de'],
37 [
'obj_id' => 2,
'title' =>
'de'],
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');
45 $activity = $this->
createActivity($lng_objects, $obj_language_factory);
47 $this->expectException(\RuntimeException::class);
48 $this->expectExceptionMessageMatches(
'/"de"/');
51 $activity->perform([
'language_keys' =>
'de']);
53 $this->assertSame([], $factory_calls);
63 $ambiguous_title =
'de';
64 $lng_objects =
static fn(): array => [
65 [
'obj_id' => 1,
'title' => $ambiguous_title],
66 [
'obj_id' => 2,
'title' => $ambiguous_title],
68 $obj_language_factory =
static function (
int $id): never {
69 throw new \LogicException(
'must never be called for an ambiguous title');
72 $activity = $this->
createActivity($lng_objects, $obj_language_factory);
75 $activity->perform([
'language_keys' => $ambiguous_title]);
76 $this->fail(
'Expected an AmbiguousLanguageTitleException to be thrown.');
78 $this->assertStringContainsString($ambiguous_title,
$e->getMessage());
79 $this->assertStringNotContainsString(
'<script>',
$e->getMessage());
80 $this->assertStringNotContainsString(
'"',
$e->getMessage());
89 $rbac = $this->createStub(\ilRbacSystem::class);
90 $rbac->method(
'checkAccessOfUser')->willReturn(
true);
92 $lng_objects =
static fn(): array => [
93 [
'obj_id' => 1,
'title' =>
'de'],
94 [
'obj_id' => 2,
'title' =>
'de'],
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');
102 $result = $this->
createActivity($lng_objects, $obj_language_factory, $rbac)
103 ->maybePerformAs($this->createRealFieldsUiFactory()->input(), 6, [
'language_keys' =>
'de']);
105 $this->assertTrue($result->isError());
106 $this->assertInstanceOf(\RuntimeException::class, $result->error());
107 $this->assertSame([], $factory_calls);
115 $lng_objects =
static fn(): array => [
116 [
'obj_id' => 1,
'title' =>
'de'],
117 [
'obj_id' => 2,
'title' =>
'de'],
118 [
'obj_id' => 3,
'title' =>
'fr'],
126 throw new \LogicException(
'must never be called for the ambiguous "de" title');
129 $activity = $this->
createActivity($lng_objects, $obj_language_factory);
131 $result = $activity->perform([
'language_keys' =>
'fr']);
133 $this->assertSame([
'fr'], $result[
'removed_local_changes_language_keys']);
134 $this->assertSame(1, $fr->removeLocalChangesCallCount());
144 $lng_objects =
static fn(): array => [
145 [
'obj_id' => 1,
'title' =>
'de'],
146 [
'obj_id' => 2,
'title' =>
'fr'],
147 [
'obj_id' => 3,
'title' =>
'fr'],
151 $factory_calls[] =
$id;
156 throw new \LogicException(
'must never be called for the ambiguous "fr" title');
159 $activity = $this->
createActivity($lng_objects, $obj_language_factory);
163 $activity->perform([
'language_keys' =>
'de,fr']);
164 $this->fail(
'Expected an AmbiguousLanguageTitleException to be thrown.');
166 $this->assertStringContainsString(
'"fr"',
$e->getMessage());
168 $this->assertSame([], $factory_calls);
169 $this->assertSame(0, $de->removeLocalChangesCallCount());
178 $rbac = $this->createStub(\ilRbacSystem::class);
179 $rbac->method(
'checkAccessOfUser')->willReturn(
true);
183 $lng_objects =
static fn(): array => [
184 [
'obj_id' => 1,
'title' =>
'de'],
185 [
'obj_id' => 2,
'title' =>
'fr'],
186 [
'obj_id' => 3,
'title' =>
'fr'],
193 throw new \LogicException(
'must never be called for the ambiguous "fr" title');
196 $result = $this->
createActivity($lng_objects, $obj_language_factory, $rbac)
197 ->maybePerformAs($this->createRealFieldsUiFactory()->input(), 6, [
'language_keys' => [
'de',
'fr']]);
199 $this->assertTrue($result->isError());
200 $this->assertInstanceOf(AmbiguousLanguageTitleException::class, $result->error());
201 $this->assertSame(0, $de->removeLocalChangesCallCount());
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Stand-in for \ilObjLanguage, which needs the global $DIC; injected via RemoveLocalLanguageChanges's $...
testAmbiguousTitleRejectsTheRequestAndNeverCallsTheObjectFactoryForIt()
testAmbiguousTitleViaMaybePerformAsReturnsResultErrorAndNeverCallsTheObjectFactory()
Via maybePerformAs() the exception must surface as a Result\Error, and the object factory stays untou...
testAnUnambiguousKeyBeforeAnAmbiguousOneNeverHasLocalChangesRemovedOnceTheWholeRequestIsRejected()
The ambiguity check runs for all requested keys before any removeLocalChanges() call.
testMaybePerformAsNeverRemovesLocalChangesForAnUnambiguousKeyWhenAnotherRequestedKeyIsAmbiguous()
Same, end-to-end through maybePerformAs().
testAmbiguousTitleExceptionMessageContainsTheRawUnescapedTitle()
The exception message embeds the ambiguous title unescaped: escaping is RendersActivityErrors::activi...
testUnambiguousLanguageKeyStillWorksAlongsideAnAmbiguousOneInTheSameLngObjectsList()
An ambiguous title must not affect a unique language key in the same request.
Class ilLanguageBaseTest.
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,)
trait RemoveLocalLanguageChangesTestFixture