19declare(strict_types=1);
32use PHPUnit\Framework\Attributes\DataProvider;
40 use RealFieldsUiFactory;
48 $rbac = $this->createMock(\ilRbacSystem::class);
49 $rbac->expects($this->never())->method(
'checkAccessOfUser');
56 $result = $activity->maybePerformAs($this->createRealFieldsUiFactory()->input(), 6, []);
58 $this->assertTrue($result->isError());
60 $this->assertInstanceOf(\RuntimeException::class,
$error);
61 $this->assertSame(500,
$error->getCode());
62 $this->assertSame(
'The activity could not be performed.',
$error->
getMessage());
63 $this->assertInstanceOf(\RuntimeException::class,
$error->getPrevious());
64 $this->assertSame(
'simulated failure while building the input description',
$error->getPrevious()->
getMessage());
71 $this->
rbacOf($this->createMock(\ilRbacSystem::class)),
73 throw_type_error:
true,
76 $error = $activity->maybePerformAs($this->createRealFieldsUiFactory()->input(), 6, [])->error();
78 $this->assertInstanceOf(\RuntimeException::class,
$error);
79 $this->assertSame(500,
$error->getCode());
81 $this->assertInstanceOf(\TypeError::class,
$error->getPrevious());
88 $this->
rbacOf($this->createMock(\ilRbacSystem::class)),
90 $this->createMock(FormInput::class),
93 $error = $activity->maybePerformAs($this->createRealFieldsUiFactory()->input(), 6, [])->error();
95 $this->assertSame(500,
$error->getCode());
96 $this->assertInstanceOf(\LogicException::class,
$error->getPrevious());
102 return [
'zero' => [0],
'negative' => [-1],
'anonymous' => [
null]];
106 #[DataProvider('unknownUserIdProvider')]
109 if (!defined(
'ANONYMOUS_USER_ID')) {
110 define(
'ANONYMOUS_USER_ID', 13);
114 $rbac_system = $this->createMock(\ilRbacSystem::class);
115 $rbac_system->expects($this->never())->method(
'checkAccessOfUser');
118 $this->
rbacOf($rbac_system),
122 $this->assertFalse($activity->isAllowedToPerform($usr_id, []));
127 $rbac_system = $this->createMock(\ilRbacSystem::class);
128 $rbac_system->expects($this->never())->method(
'checkAccessOfUser');
131 $this->
rbacOf($rbac_system),
135 $error = $activity->maybePerformAs($this->createRealFieldsUiFactory()->input(), 0, [])->error();
137 $this->assertSame(403,
$error->getCode());
146 $rbac = $this->createStub(\ilRbacSystem::class);
147 $rbac->method(
'checkAccessOfUser')->willReturn(
true);
154 $result = $activity->maybePerformAs($this->createRealFieldsUiFactory()->input(), 42, []);
156 $this->assertFalse($result->isError());
173 'tos#:#x' =>
$policy->findViolations(
'<script>a</script><script>b</script></form>'),
176 'en' => [
'tos#:#y' =>
$policy->findViolations(
'<script>a</script>')],
177 'fr' => [
'tos#:#z' =>
$policy->findViolations(
'<script>a</script>')],
180 $this->
rbacOf($this->createStub(\ilRbacSystem::class)),
185 [
'en: tos#:#y: <script>',
'de: tos#:#x: <script>, </form>',
'de: tos#:#plain'],
186 $activity->entries($skipped, [
'en',
'de',
'it'])
193 'de' => [
'tos#:#x' => [
'common: x',
'pilot: X'],
'tos#:#y' => [
'mme: y']],
194 'en' => [
'tos#:#z' => [
'mme: z']],
195 'fr' => [
'tos#:#z' => [
'mme: z']],
198 $this->
rbacOf($this->createStub(\ilRbacSystem::class)),
203 [
'en: tos#:#z (mme: z)',
'de: tos#:#x (common: x, pilot: X)',
'de: tos#:#y (mme: y)'],
204 $activity->duplicateEntries($skipped, [
'en',
'de',
'it'])
214 private readonly
bool $throw_type_error =
false,
221 return $this->data->text()->markdown()->simpleDocument(
'Test double for LanguageActivity::maybePerformAs().');
226 if ($this->throw_type_error) {
227 throw new \TypeError(
'simulated TypeError while building the input description');
230 throw new \RuntimeException(
'simulated failure while building the input description');
235 throw new \LogicException(__METHOD__ .
' is not used by this test double.');
240 throw new \LogicException(__METHOD__ .
' is not used by this test double.');
245 throw new \LogicException(__METHOD__ .
' is not used by this test double.');
258 private readonly ?
FormInput $description =
null,
265 return $this->data->text()->markdown()->simpleDocument(
'Test double for the usr_id precedence in maybePerformAs().');
270 return $this->description ??
$f->group([]);
275 throw new \LogicException(__METHOD__ .
' is not used by this test double.');
289 return [
'usr_id' =>
'SPOOFED-VALUE',
'source' =>
'form'];
303 public function entries(array $skipped, array $language_keys): array
320 return $this->data->text()->markdown()->simpleDocument(
'Test double for invalidMarkupCustomizingEntries().');
325 throw new \LogicException(__METHOD__ .
' is not used by this test double.');
330 throw new \LogicException(__METHOD__ .
' is not used by this test double.');
335 throw new \LogicException(__METHOD__ .
' is not used by this test double.');
343 throw new \LogicException(__METHOD__ .
' is not used by this test double.');
This describes some datastructure in terms of standard data structures such as primitives,...
duplicateCustomizingEntries(array $skipped, array $language_keys)
invalidMarkupCustomizingEntries(array $skipped, array $language_keys)
The HTML a translation value may contain, decided in one place for the shipped files (cleaned in Setu...
Minimal LanguageActivity making the protected invalidMarkupCustomizingEntries() callable.
getOutputDescription(Description\Factory $f)
normalizeParameters(array $grind_result)
perform(mixed $parameters)
This shall perform the activity.
duplicateEntries(array $skipped, array $language_keys)
getInputDescription(FieldFactory $f)
entries(array $skipped, array $language_keys)
Targets LanguageActivity::maybePerformAs() directly via throwing test doubles, for behaviour no concr...
testDuplicateCustomizingEntriesNameWhatEachEntryWouldDuplicate()
testMaybePerformAsPassesTheTrustedUsrIdToPerformOverASpoofedFormKey()
perform() gets the usr_id of maybePerformAs(), not the spoofed one from normalizeParameters().
testExceptionWhileBuildingTheInputDescriptionIsMaskedAsA500ResultError()
A defect while building the input description comes back masked as 500 (original only as previous),...
testADefectThrownByGrindIsMaskedAsA500ResultError()
grind() throws on a defect (FormInput without InputInternal); maybePerformAs() must mask it as 500.
testMaybePerformAsAnswers403ForANonUserAndNeverPerforms()
testATypeErrorWhileBuildingTheInputDescriptionIsMaskedAsA500ResultError()
A non-\Exception \Throwable (\TypeError) is masked as well.
testIsAllowedToPerformRefusesNonUsersWithoutAskingRbac(?int $usr_id)
No RBAC lookup for a non-user: the anonymous user (null: ANONYMOUS_USER_ID) must not pass on its role...
static unknownUserIdProvider()
testInvalidMarkupCustomizingEntriesAppendTheMarkupConcernedToEachEntry()
Skipped entries are listed with their markup, language-neutral and without duplicates; only the reque...
Class ilLanguageBaseTest.
rbacOf(\ilRbacSystem $system)
languageFolder(int $ref_id=0)
Public RBAC service of the AccessControl component.
The language folder in the administration, whose "write" permission guards the language Activities.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...