19declare(strict_types=1);
20use PHPUnit\Framework\TestCase;
29 protected function setUp(): void
34 if (!defined(
'SYSTEM_FOLDER_ID')) {
35 define(
'SYSTEM_FOLDER_ID', 42);
37 if (!defined(
'ROOT_FOLDER_ID')) {
38 define(
'ROOT_FOLDER_ID', 24);
52 $DIC[
'rbacsystem'] = $rbac_mock = $this->createMock(ilRbacSystem::class);
55 $rbac_mock->expects($this->once())
56 ->method(
'hasAnyAdminReadPermission')
59 $this->assertTrue($class->hasAdministrationAccess()());
61 $class->hasAdministrationAccess()()
68 $DIC[
'rbacsystem'] = $rbac_mock = $this->createMock(ilRbacSystem::class);
71 $rbac_mock->expects($this->once())
72 ->method(
'hasAnyAdminReadPermission')
75 $this->assertFalse($class->hasAdministrationAccess()());
77 $class->hasAdministrationAccess()()
84 $DIC[
'rbacsystem'] = $rbac_mock = $this->createMock(ilRbacSystem::class);
87 $rbac_mock->expects($this->once())
88 ->method(
'hasAnyAdminReadPermission')
91 $closure_returning_false = fn():
bool =>
false;
93 $this->assertTrue($class->hasAdministrationAccess()());
95 $class->hasAdministrationAccess($closure_returning_false)()
103 $DIC[
'ilUser'] = $user_mock = $this->createMock(ilObjUser::class);
104 $DIC[
'ilSetting'] = $settings_mock = $this->createMock(ilSetting::class);
105 $DIC[
'ilAccess'] = $access_mock = $this->createMock(ilAccessHandler::class);
109 $user_mock->expects($this->once())
110 ->method(
'isAnonymous')
113 $settings_mock->expects($this->once())
115 ->with(
'pub_section')
118 $access_mock->expects($this->once())
119 ->method(
'checkAccessOfUser')
120 ->with($this->isType(
'integer'),
'read',
'', $this->
ROOT_FOLDER_ID)
123 $this->assertTrue($class->isRepositoryReadable()());
125 $class->isRepositoryReadable()()
128 $class->isRepositoryReadable(fn():
bool =>
true)()
131 $class->isRepositoryReadable(fn():
bool =>
false)()
139 $DIC[
'ilUser'] = $user_mock = $this->createMock(ilObjUser::class);
140 $DIC[
'ilSetting'] = $settings_mock = $this->createMock(ilSetting::class);
141 $DIC[
'ilAccess'] = $access_mock = $this->createMock(ilAccessHandler::class);
145 $user_mock->expects($this->once())
146 ->method(
'isAnonymous')
149 $settings_mock->expects($this->once())
151 ->with(
'pub_section')
154 $access_mock->expects($this->never())
155 ->method(
'checkAccessOfUser');
157 $this->assertFalse($class->isRepositoryReadable()());
159 $class->isRepositoryReadable()()
162 $class->isRepositoryReadable(fn():
bool =>
true)()
165 $class->isRepositoryReadable(fn():
bool =>
false)()
173 $DIC[
'ilUser'] = $user_mock = $this->createMock(ilObjUser::class);
174 $DIC[
'ilSetting'] = $settings_mock = $this->createMock(ilSetting::class);
175 $DIC[
'ilAccess'] = $access_mock = $this->createMock(ilAccessHandler::class);
179 $user_mock->expects($this->once())
180 ->method(
'isAnonymous')
183 $user_mock->expects($this->once())
187 $settings_mock->expects($this->never())
190 $access_mock->expects($this->once())
191 ->method(
'checkAccess')
195 $this->assertTrue($class->isRepositoryReadable()());
197 $class->isRepositoryReadable()()
200 $class->isRepositoryReadable(fn():
bool =>
true)()
203 $class->isRepositoryReadable(fn():
bool =>
false)()
211 $DIC[
'ilUser'] = $user_mock = $this->createMock(ilObjUser::class);
212 $DIC[
'ilSetting'] = $settings_mock = $this->createMock(ilSetting::class);
213 $DIC[
'ilAccess'] = $access_mock = $this->createMock(ilAccessHandler::class);
217 $user_mock->expects($this->once())
218 ->method(
'isAnonymous')
221 $user_mock->expects($this->once())
225 $settings_mock->expects($this->never())
228 $access_mock->expects($this->once())
229 ->method(
'checkAccess')
233 $this->assertFalse($class->isRepositoryReadable()());
235 $class->isRepositoryReadable()()
238 $class->isRepositoryReadable(fn():
bool =>
true)()
241 $class->isRepositoryReadable(fn():
bool =>
false)()
Customizing of pimple-DIC for ILIAS.
Class BasicAccessCheckClosures.
testRepoAccessTrueNotLoggedInPublicSection()
testRepoAccessTrueLoggedIn()
testRepoAccessTrueNotLoggedInNoPublicSection()
testRepoAccessFalseLoggedIn()
testAdminAcessTrueButWithClosure()