19declare(strict_types=1);
25use PHPUnit\Framework\MockObject\MockObject;
27require_once
"Base.php";
35 private \ilTree|MockObject
$tree;
36 private \ilAccessHandler|MockObject
$access;
38 protected function setUp(): void
40 $this->container = $this->createMock(Container::class);
41 $this->tree = $this->createMock(\ilTree::class);
42 $this->
access = $this->createMock(\ilAccessHandler::class);
43 $this->container->method(
'repositoryTree')->willReturn($this->tree);
44 $this->container->method(
'access')->willReturn($this->
access);
49 $this->tree->method(
'isInTree')->willReturn(
false);
50 $context =
new Context($this->container);
52 $this->assertNull($context->findFirstAccessibleParentRefId(0));
53 $this->assertNull($context->findFirstAccessibleParentRefId(-5));
54 $this->assertNull($context->findFirstAccessibleParentRefId(42));
59 $this->tree->method(
'isInTree')->willReturn(
true);
60 $this->tree->method(
'getRootId')->willReturn(1);
61 $this->tree->method(
'getParentId')->willReturnMap([
64 $this->
access->method(
'checkAccess')->willReturnCallback(
65 static fn(
string $perm,
string $_,
int $ref_id):
bool => $perm ===
'read' &&
$ref_id === 50
68 $context =
new Context($this->container);
70 $this->assertSame(50, $context->findFirstAccessibleParentRefId(100));
75 $this->tree->method(
'isInTree')->willReturn(
true);
76 $this->tree->method(
'getRootId')->willReturn(1);
77 $this->tree->method(
'getParentId')->willReturnMap([
82 $this->
access->method(
'checkAccess')->willReturnCallback(
83 static fn(
string $perm,
string $_,
int $ref_id):
bool => $perm ===
'read' &&
$ref_id === 40
86 $context =
new Context($this->container);
88 $this->assertSame(40, $context->findFirstAccessibleParentRefId(100));
93 $this->tree->method(
'isInTree')->willReturn(
true);
94 $this->tree->method(
'getRootId')->willReturn(1);
95 $this->tree->method(
'getParentId')->willReturnMap([
100 $this->
access->method(
'checkAccess')->willReturn(
false);
102 $context =
new Context($this->container);
104 $this->assertNull($context->findFirstAccessibleParentRefId(100));
109 $this->tree->method(
'isInTree')->willReturn(
true);
110 $this->tree->method(
'getRootId')->willReturn(1);
111 $this->tree->method(
'getParentId')->willReturnMap([
114 $this->
access->method(
'checkAccess')->willReturn(
false);
116 $context =
new Context($this->container);
118 $this->assertNull($context->findFirstAccessibleParentRefId(100));
123 $this->tree->method(
'isInTree')->willReturn(
true);
124 $this->tree->method(
'getRootId')->willReturn(1);
125 $this->tree->method(
'getParentId')->willReturnMap([
129 $this->
access->method(
'checkAccess')->willReturn(
false);
131 $context =
new Context($this->container);
133 $this->assertNull($context->findFirstAccessibleParentRefId(100));
138 $this->tree->method(
'isInTree')->willReturn(
true);
139 $this->tree->method(
'getRootId')->willReturn(1);
140 $this->tree->method(
'getParentId')->willReturnMap([
143 $this->
access->method(
'checkAccess')->willReturnCallback(
144 static fn(
string $perm,
string $_,
int $ref_id):
bool => $perm ===
'visible' &&
$ref_id === 80
147 $context =
new Context($this->container);
149 $this->assertNull($context->findFirstAccessibleParentRefId(100));
150 $this->assertSame(80, $context->findFirstAccessibleParentRefId(100,
'visible'));
Customizing of pimple-DIC for ILIAS.
testFindFirstAccessibleParentWalksUntilReadPermissionFound()
testFindFirstAccessibleParentHandlesCycle()
testFindFirstAccessibleParentReturnsNullForInvalidRefId()
testFindFirstAccessibleParentReturnsNullWhenNoParentReadable()
ilAccessHandler MockObject $access
testFindFirstAccessibleParentStopsAtRoot()
testFindFirstAccessibleParentReturnsDirectReadableParent()
testFindFirstAccessibleParentHonoursCustomPermission()
Container MockObject $container
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...