ILIAS  release_8 Revision v8.24
ilObjChatroomAccessTest Class Reference

Class ilObjChatroomAccessTest. More...

+ Inheritance diagram for ilObjChatroomAccessTest:
+ Collaboration diagram for ilObjChatroomAccessTest:

Public Member Functions

 testCommandDefitionFullfilsExpectations ()
 
 testGotoCheckFails ()
 
 testGotoCheckSucceeds ()
 
 testAccessChecksFail ()
 
 testAccessChecksSucceed ()
 

Protected Member Functions

 setUp ()
 
- Protected Member Functions inherited from ilChatroomAbstractTest
 setUp ()
 
 tearDown ()
 
 createIlChatroomMock ()
 
 createIlChatroomUserMock ()
 
 createGlobalIlDBMock ()
 
 setGlobalVariable (string $name, $value)
 

Protected Attributes

ilObjChatroomAccess $access
 
ilDBInterface $db
 
- Protected Attributes inherited from ilChatroomAbstractTest
 $ilChatroomMock
 
 $ilChatroomUserMock
 

Detailed Description

Member Function Documentation

◆ setUp()

ilObjChatroomAccessTest::setUp ( )
protected

Reimplemented from ilChatroomAbstractTest.

Definition at line 210 of file class.ilObjChatroomAccessTest.php.

210 : void
211 {
212 parent::setUp();
213
214 $settingsReflection = new ReflectionClass(ilSetting::class);
215 $cache = $settingsReflection->getProperty('settings_cache');
216 $cache->setAccessible(true);
217 $cache->setValue($settingsReflection, []);
218
219 $this->access = new ilObjChatroomAccess();
220 $this->db = $this->createGlobalIlDBMock();
221 }
Access class for chatroom objects.

References ILIAS\Repository\access(), and ilChatroomAbstractTest\createGlobalIlDBMock().

+ Here is the call graph for this function:

◆ testAccessChecksFail()

ilObjChatroomAccessTest::testAccessChecksFail ( )

Definition at line 151 of file class.ilObjChatroomAccessTest.php.

151 : void
152 {
153 $userId = 1;
154 $refId = 99;
155 $objId = 6;
156
157 $user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->onlyMethods(
158 ['getId']
159 )->getMock();
160 $user->expects($this->once())->method('getId')->willReturn($userId);
161
162 $this->setGlobalVariable('ilUser', $user);
163
164 $rbacsystem = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->onlyMethods(
165 ['checkAccessOfUser']
166 )->getMock();
167 $rbacsystem->expects($this->once())->method('checkAccessOfUser')->with(
168 $this->equalTo($userId),
169 $this->equalTo('write'),
170 $this->equalTo($refId)
171 )->willReturn(false);
172
173 $this->setGlobalVariable('rbacsystem', $rbacsystem);
174
175 $this->assertFalse($this->access->_checkAccess('unused', 'write', $refId, $objId));
176 }
setGlobalVariable(string $name, $value)
$objId
Definition: xapitoken.php:57
$refId
Definition: xapitoken.php:58

References $objId, $refId, ILIAS\Repository\access(), and ilChatroomAbstractTest\setGlobalVariable().

+ Here is the call graph for this function:

◆ testAccessChecksSucceed()

ilObjChatroomAccessTest::testAccessChecksSucceed ( )

Definition at line 178 of file class.ilObjChatroomAccessTest.php.

178 : void
179 {
180 $userId = 1;
181 $refId = 99;
182 $objId = 6;
183
184 $user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->onlyMethods(
185 ['getId']
186 )->getMock();
187 $user->expects($this->once())->method('getId')->willReturn($userId);
188
189 $this->setGlobalVariable('ilUser', $user);
190
191 $this->db->method('fetchAssoc')->willReturnOnConsecutiveCalls(
192 ['keyword' => 'chat_enabled', 'value' => '0'],
193 null
194 );
195
196 $rbacsystem = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->onlyMethods(
197 ['checkAccessOfUser']
198 )->getMock();
199 $rbacsystem->expects($this->once())->method('checkAccessOfUser')->with(
200 $this->equalTo($userId),
201 $this->equalTo('write'),
202 $this->equalTo($refId)
203 )->willReturn(true);
204
205 $this->setGlobalVariable('rbacsystem', $rbacsystem);
206
207 $this->assertTrue($this->access->_checkAccess('unused', 'write', $refId, $objId));
208 }

References $objId, $refId, ILIAS\Repository\access(), and ilChatroomAbstractTest\setGlobalVariable().

+ Here is the call graph for this function:

◆ testCommandDefitionFullfilsExpectations()

ilObjChatroomAccessTest::testCommandDefitionFullfilsExpectations ( )

Definition at line 33 of file class.ilObjChatroomAccessTest.php.

33 : void
34 {
35 $expected = [
36 ['permission' => 'read', 'cmd' => 'view', 'lang_var' => 'enter', 'default' => true],
37 ['permission' => 'write', 'cmd' => 'settings-general', 'lang_var' => 'settings'],
38 ];
39
40 $commands = $this->access::_getCommands();
41
42 $this->assertIsArray($commands);
43 $this->assertSame($expected, $commands);
44 }

◆ testGotoCheckFails()

ilObjChatroomAccessTest::testGotoCheckFails ( )

Definition at line 46 of file class.ilObjChatroomAccessTest.php.

46 : void
47 {
48 $user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->onlyMethods(
49 ['getId']
50 )->getMock();
51 $user->method('getId')->willReturn(6);
52
53 $this->setGlobalVariable('ilUser', $user);
54
55 $chatroomSettings = $this->createMock(ilDBStatement::class);
56 $chatroomSettings
57 ->method('fetchAssoc')
58 ->willReturnOnConsecutiveCalls(
59 [
60 'keyword' => 'public_room_ref',
61 'value' => '1',
62 ],
63 null,
64 );
65
66 $this->db
67 ->method('fetchAssoc')
68 ->willReturnCallback(static function (ilDBStatement $statement) {
69 return $statement->fetchAssoc();
70 });
71
72 $this->db
73 ->method('query')
74 ->with($this->stringContains("FROM settings WHERE module='chatroom'", false))
75 ->willReturn($chatroomSettings);
76 $this->setGlobalVariable('ilDB', $this->db);
77
78 $rbacsystem = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->onlyMethods(
79 ['checkAccess', 'checkAccessOfUser']
80 )->getMock();
81 $rbacsystem->method('checkAccess')->with(
82 $this->logicalOr($this->equalTo('read'), $this->equalTo('visible')),
83 $this->equalTo('1')
84 )->willReturn(false);
85 $rbacsystem->method('checkAccessOfUser')->with(
86 $this->equalTo(6),
87 $this->logicalOr($this->equalTo('read'), $this->equalTo('visible')),
88 $this->equalTo('1')
89 )->willReturn(false);
90
91 $this->setGlobalVariable('rbacsystem', $rbacsystem);
92
93 $this->assertFalse($this->access::_checkGoto(''));
94 $this->assertFalse($this->access::_checkGoto('chtr'));
95 $this->assertFalse($this->access::_checkGoto('chtr_'));
96 $this->assertFalse($this->access::_checkGoto('chtr_'));
97 $this->assertFalse($this->access::_checkGoto('chtr_test'));
98 $this->assertFalse($this->access::_checkGoto('chtr_1'));
99 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References ilDBStatement\fetchAssoc(), and ilChatroomAbstractTest\setGlobalVariable().

+ Here is the call graph for this function:

◆ testGotoCheckSucceeds()

ilObjChatroomAccessTest::testGotoCheckSucceeds ( )

Definition at line 101 of file class.ilObjChatroomAccessTest.php.

101 : void
102 {
103 $user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->onlyMethods(
104 ['getId']
105 )->getMock();
106 $user->method('getId')->willReturn(6);
107
108 $this->setGlobalVariable('ilUser', $user);
109
110 $chatroomSettings = $this->createMock(ilDBStatement::class);
111 $chatroomSettings
112 ->method('fetchAssoc')
113 ->willReturnOnConsecutiveCalls(
114 [
115 'keyword' => 'public_room_ref',
116 'value' => '5',
117 ],
118 null
119 );
120
121 $this->db
122 ->method('fetchAssoc')
123 ->willReturnCallback(static function (ilDBStatement $statement) {
124 return $statement->fetchAssoc();
125 });
126
127 $this->db
128 ->method('query')
129 ->with($this->stringContains("FROM settings WHERE module='chatroom'", false))
130 ->willReturn($chatroomSettings);
131 $this->setGlobalVariable('ilDB', $this->db);
132
133 $rbacsystem = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->onlyMethods(
134 ['checkAccess', 'checkAccessOfUser']
135 )->getMock();
136 $rbacsystem->method('checkAccess')->with(
137 $this->logicalOr($this->equalTo('read'), $this->equalTo('visible'), $this->equalTo('write')),
138 $this->equalTo('5')
139 )->willReturn(true);
140 $rbacsystem->method('checkAccessOfUser')->with(
141 $this->equalTo(6),
142 $this->logicalOr($this->equalTo('read'), $this->equalTo('visible'), $this->equalTo('write')),
143 $this->equalTo('5')
144 )->willReturn(true);
145
146 $this->setGlobalVariable('rbacsystem', $rbacsystem);
147
148 $this->assertTrue($this->access::_checkGoto('chtr_5'));
149 }

References ilDBStatement\fetchAssoc(), and ilChatroomAbstractTest\setGlobalVariable().

+ Here is the call graph for this function:

Field Documentation

◆ $access

ilObjChatroomAccess ilObjChatroomAccessTest::$access
protected

Definition at line 29 of file class.ilObjChatroomAccessTest.php.

◆ $db

ilDBInterface ilObjChatroomAccessTest::$db
protected

Definition at line 31 of file class.ilObjChatroomAccessTest.php.


The documentation for this class was generated from the following file: