19declare(strict_types=1);
20use PHPUnit\Framework\MockObject\MockObject;
21use PHPUnit\Framework\TestCase;
31 protected function setUp(): void
36 if (!defined(
'SYSTEM_FOLDER_ID')) {
37 define(
'SYSTEM_FOLDER_ID', 42);
40 if (!defined(
'ROOT_FOLDER_ID')) {
41 define(
'ROOT_FOLDER_ID', 24);
55 $DIC[
'rbacsystem'] = $rbac_mock = $this->createMock(ilRbacSystem::class);
58 $rbac_mock->expects($this->once())
59 ->method(
'checkAccess')
63 $this->assertTrue($class->hasAdministrationAccess()());
65 $class->hasAdministrationAccess()()
72 $DIC[
'rbacsystem'] = $rbac_mock = $this->createMock(ilRbacSystem::class);
75 $rbac_mock->expects($this->once())
76 ->method(
'checkAccess')
80 $this->assertFalse($class->hasAdministrationAccess()());
82 $class->hasAdministrationAccess()()
89 $DIC[
'rbacsystem'] = $rbac_mock = $this->createMock(ilRbacSystem::class);
92 $rbac_mock->expects($this->once())
93 ->method(
'checkAccess')
97 $closure_returning_false = fn():
bool =>
false;
99 $this->assertTrue($class->hasAdministrationAccess()());
101 $class->hasAdministrationAccess($closure_returning_false)()
109 $DIC[
'ilUser'] = $user_mock = $this->createMock(ilObjUser::class);
110 $DIC[
'ilSetting'] = $settings_mock = $this->createMock(ilSetting::class);
111 $DIC[
'ilAccess'] = $access_mock = $this->createMock(ilAccessHandler::class);
115 $user_mock->expects($this->once())
116 ->method(
'isAnonymous')
119 $settings_mock->expects($this->once())
121 ->with(
'pub_section')
124 $access_mock->expects($this->once())
125 ->method(
'checkAccessOfUser')
126 ->with($this->isType(
'integer'),
'read',
'', $this->
ROOT_FOLDER_ID)
129 $this->assertTrue($class->isRepositoryReadable()());
131 $class->isRepositoryReadable()()
134 $class->isRepositoryReadable(fn():
bool =>
true)()
137 $class->isRepositoryReadable(fn():
bool =>
false)()
145 $DIC[
'ilUser'] = $user_mock = $this->createMock(ilObjUser::class);
146 $DIC[
'ilSetting'] = $settings_mock = $this->createMock(ilSetting::class);
147 $DIC[
'ilAccess'] = $access_mock = $this->createMock(ilAccessHandler::class);
151 $user_mock->expects($this->once())
152 ->method(
'isAnonymous')
155 $settings_mock->expects($this->once())
157 ->with(
'pub_section')
160 $access_mock->expects($this->never())
161 ->method(
'checkAccessOfUser');
163 $this->assertFalse($class->isRepositoryReadable()());
165 $class->isRepositoryReadable()()
168 $class->isRepositoryReadable(fn():
bool =>
true)()
171 $class->isRepositoryReadable(fn():
bool =>
false)()
179 $DIC[
'ilUser'] = $user_mock = $this->createMock(ilObjUser::class);
180 $DIC[
'ilSetting'] = $settings_mock = $this->createMock(ilSetting::class);
181 $DIC[
'ilAccess'] = $access_mock = $this->createMock(ilAccessHandler::class);
185 $user_mock->expects($this->once())
186 ->method(
'isAnonymous')
189 $user_mock->expects($this->once())
193 $settings_mock->expects($this->never())
196 $access_mock->expects($this->once())
197 ->method(
'checkAccess')
201 $this->assertTrue($class->isRepositoryReadable()());
203 $class->isRepositoryReadable()()
206 $class->isRepositoryReadable(fn():
bool =>
true)()
209 $class->isRepositoryReadable(fn():
bool =>
false)()
217 $DIC[
'ilUser'] = $user_mock = $this->createMock(ilObjUser::class);
218 $DIC[
'ilSetting'] = $settings_mock = $this->createMock(ilSetting::class);
219 $DIC[
'ilAccess'] = $access_mock = $this->createMock(ilAccessHandler::class);
223 $user_mock->expects($this->once())
224 ->method(
'isAnonymous')
227 $user_mock->expects($this->once())
231 $settings_mock->expects($this->never())
234 $access_mock->expects($this->once())
235 ->method(
'checkAccess')
239 $this->assertFalse($class->isRepositoryReadable()());
241 $class->isRepositoryReadable()()
244 $class->isRepositoryReadable(fn():
bool =>
true)()
247 $class->isRepositoryReadable(fn():
bool =>
false)()
Customizing of pimple-DIC for ILIAS.
Class BasicAccessCheckClosures.
testRepoAccessTrueNotLoggedInPublicSection()
testRepoAccessTrueLoggedIn()
testRepoAccessTrueNotLoggedInNoPublicSection()
testRepoAccessFalseLoggedIn()
testAdminAcessTrueButWithClosure()