ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
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 ilChatroomAbstractTestBase
 setUp ()
 
 tearDown ()
 
 createIlChatroomUserMock ()
 
 createGlobalIlDBMock ()
 
 setGlobalVariable (string $name, $value)
 

Protected Attributes

ilObjChatroomAccess $access
 
ilDBInterface &MockObject $db
 
- Protected Attributes inherited from ilChatroomAbstractTestBase
MockObject &ilChatroom $ilChatroomMock
 
MockObject &ilChatroomUser $ilChatroomUserMock
 

Detailed Description

Member Function Documentation

◆ setUp()

ilObjChatroomAccessTest::setUp ( )
protected

Reimplemented from ilChatroomAbstractTestBase.

Definition at line 218 of file ilObjChatroomAccessTest.php.

218 : void
219 {
220 parent::setUp();
221
222 $settingsReflection = new ReflectionClass(ilSetting::class);
223 $cache = $settingsReflection->getProperty('settings_cache');
224 $cache->setValue($settingsReflection, []);
225
226 $this->access = new ilObjChatroomAccess();
227 $this->db = $this->createGlobalIlDBMock();
228 }
Access class for chatroom objects.

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

+ Here is the call graph for this function:

◆ testAccessChecksFail()

ilObjChatroomAccessTest::testAccessChecksFail ( )

Definition at line 159 of file ilObjChatroomAccessTest.php.

159 : void
160 {
161 $userId = 1;
162 $refId = 99;
163 $objId = 6;
164
165 $user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->onlyMethods(
166 ['getId']
167 )->getMock();
168 $user->expects($this->once())->method('getId')->willReturn($userId);
169
170 $this->setGlobalVariable('ilUser', $user);
171
172 $rbacsystem = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->onlyMethods(
173 ['checkAccessOfUser']
174 )->getMock();
175 $rbacsystem->expects($this->once())->method('checkAccessOfUser')->with(
176 $this->equalTo($userId),
177 $this->equalTo('write'),
178 $this->equalTo($refId)
179 )->willReturn(false);
180
181 $this->setGlobalVariable('rbacsystem', $rbacsystem);
182
183 $this->assertFalse($this->access->_checkAccess('unused', 'write', $refId, $objId));
184 }
$objId
Definition: xapitoken.php:55
$refId
Definition: xapitoken.php:56

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

+ Here is the call graph for this function:

◆ testAccessChecksSucceed()

ilObjChatroomAccessTest::testAccessChecksSucceed ( )

Definition at line 186 of file ilObjChatroomAccessTest.php.

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

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

+ Here is the call graph for this function:

◆ testCommandDefitionFullfilsExpectations()

ilObjChatroomAccessTest::testCommandDefitionFullfilsExpectations ( )

Definition at line 32 of file ilObjChatroomAccessTest.php.

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

◆ testGotoCheckFails()

ilObjChatroomAccessTest::testGotoCheckFails ( )

Definition at line 45 of file ilObjChatroomAccessTest.php.

45 : void
46 {
47 $user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->onlyMethods(
48 ['getId']
49 )->getMock();
50 $user->method('getId')->willReturn(6);
51
52 $this->setGlobalVariable('ilObjDataCache', $this->createMock(ilObjectDataCache::class));
53
54 $this->setGlobalVariable('ilUser', $user);
55
56 $chatroomSettings = $this->createMock(ilDBStatement::class);
57 $chatroomSettings
58 ->expects($this->exactly(2))
59 ->method('fetchAssoc')
60 ->willReturnOnConsecutiveCalls(
61 [
62 'keyword' => 'public_room_ref',
63 'value' => '1',
64 ],
65 null,
66 );
67
68 $this->db
69 ->expects($this->atLeastOnce())
70 ->method('fetchAssoc')
71 ->willReturnCallback(static fn(ilDBStatement $statement) => $statement->fetchAssoc());
72
73 $this->db
74 ->expects($this->once())
75 ->method('query')
76 ->with($this->stringContains("FROM settings WHERE module='chatroom'", false))
77 ->willReturn($chatroomSettings);
78 $this->setGlobalVariable('ilDB', $this->db);
79
80 $rbacsystem = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->onlyMethods(
81 ['checkAccess', 'checkAccessOfUser']
82 )->getMock();
83 $rbacsystem
84 ->expects($this->never())
85 ->method('checkAccess');
86 $rbacsystem
87 ->expects($this->atLeastOnce())
88 ->method('checkAccessOfUser')
89 ->with(
90 $this->equalTo(6),
91 $this->logicalOr($this->equalTo('read'), $this->equalTo('visible')),
92 $this->equalTo('1')
93 )->willReturn(false);
94
95 $this->setGlobalVariable('rbacsystem', $rbacsystem);
96
97 $this->assertFalse($this->access::_checkGoto(''));
98 $this->assertFalse($this->access::_checkGoto('chtr'));
99 $this->assertFalse($this->access::_checkGoto('chtr_'));
100 $this->assertFalse($this->access::_checkGoto('chtr_'));
101 $this->assertFalse($this->access::_checkGoto('chtr_test'));
102 $this->assertFalse($this->access::_checkGoto('chtr_1'));
103 }
Interface ilDBStatement.

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

+ Here is the call graph for this function:

◆ testGotoCheckSucceeds()

ilObjChatroomAccessTest::testGotoCheckSucceeds ( )

Definition at line 105 of file ilObjChatroomAccessTest.php.

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

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

+ Here is the call graph for this function:

Field Documentation

◆ $access

ilObjChatroomAccess ilObjChatroomAccessTest::$access
protected

Definition at line 29 of file ilObjChatroomAccessTest.php.

◆ $db

ilDBInterface& MockObject ilObjChatroomAccessTest::$db
protected

Definition at line 30 of file ilObjChatroomAccessTest.php.


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