ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
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

Definition at line 208 of file ilObjChatroomAccessTest.php.

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

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

◆ testAccessChecksFail()

ilObjChatroomAccessTest::testAccessChecksFail ( )

Definition at line 149 of file ilObjChatroomAccessTest.php.

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

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

◆ testAccessChecksSucceed()

ilObjChatroomAccessTest::testAccessChecksSucceed ( )

Definition at line 176 of file ilObjChatroomAccessTest.php.

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

176  : void
177  {
178  $userId = 1;
179  $refId = 99;
180  $objId = 6;
181 
182  $user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->onlyMethods(
183  ['getId']
184  )->getMock();
185  $user->expects($this->once())->method('getId')->willReturn($userId);
186 
187  $this->setGlobalVariable('ilUser', $user);
188 
189  $this->db->method('fetchAssoc')->willReturnOnConsecutiveCalls(
190  ['keyword' => 'chat_enabled', 'value' => '0'],
191  null
192  );
193 
194  $rbacsystem = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->onlyMethods(
195  ['checkAccessOfUser']
196  )->getMock();
197  $rbacsystem->expects($this->once())->method('checkAccessOfUser')->with(
198  $this->equalTo($userId),
199  $this->equalTo('write'),
200  $this->equalTo($refId)
201  )->willReturn(true);
202 
203  $this->setGlobalVariable('rbacsystem', $rbacsystem);
204 
205  $this->assertTrue($this->access->_checkAccess('unused', 'write', $refId, $objId));
206  }
$objId
Definition: xapitoken.php:57
$refId
Definition: xapitoken.php:58
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ 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.

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

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  ->method('fetchAssoc')
59  ->willReturnOnConsecutiveCalls(
60  [
61  'keyword' => 'public_room_ref',
62  'value' => '1',
63  ],
64  null,
65  );
66 
67  $this->db
68  ->method('fetchAssoc')
69  ->willReturnCallback(static fn(ilDBStatement $statement) => $statement->fetchAssoc());
70 
71  $this->db
72  ->method('query')
73  ->with($this->stringContains("FROM settings WHERE module='chatroom'", false))
74  ->willReturn($chatroomSettings);
75  $this->setGlobalVariable('ilDB', $this->db);
76 
77  $rbacsystem = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->onlyMethods(
78  ['checkAccess', 'checkAccessOfUser']
79  )->getMock();
80  $rbacsystem->method('checkAccess')->with(
81  $this->logicalOr($this->equalTo('read'), $this->equalTo('visible')),
82  $this->equalTo('1')
83  )->willReturn(false);
84  $rbacsystem->method('checkAccessOfUser')->with(
85  $this->equalTo(6),
86  $this->logicalOr($this->equalTo('read'), $this->equalTo('visible')),
87  $this->equalTo('1')
88  )->willReturn(false);
89 
90  $this->setGlobalVariable('rbacsystem', $rbacsystem);
91 
92  $this->assertFalse($this->access::_checkGoto(''));
93  $this->assertFalse($this->access::_checkGoto('chtr'));
94  $this->assertFalse($this->access::_checkGoto('chtr_'));
95  $this->assertFalse($this->access::_checkGoto('chtr_'));
96  $this->assertFalse($this->access::_checkGoto('chtr_test'));
97  $this->assertFalse($this->access::_checkGoto('chtr_1'));
98  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:

◆ testGotoCheckSucceeds()

ilObjChatroomAccessTest::testGotoCheckSucceeds ( )

Definition at line 100 of file ilObjChatroomAccessTest.php.

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

100  : void
101  {
102  $user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->onlyMethods(
103  ['getId']
104  )->getMock();
105  $user->method('getId')->willReturn(6);
106 
107  $this->setGlobalVariable('ilObjDataCache', $this->createMock(ilObjectDataCache::class));
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 fn(ilDBStatement $statement) => $statement->fetchAssoc());
124 
125  $this->db
126  ->method('query')
127  ->with($this->stringContains("FROM settings WHERE module='chatroom'", false))
128  ->willReturn($chatroomSettings);
129  $this->setGlobalVariable('ilDB', $this->db);
130 
131  $rbacsystem = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->onlyMethods(
132  ['checkAccess', 'checkAccessOfUser']
133  )->getMock();
134  $rbacsystem->method('checkAccess')->with(
135  $this->logicalOr($this->equalTo('read'), $this->equalTo('visible'), $this->equalTo('write')),
136  $this->equalTo('5')
137  )->willReturn(true);
138  $rbacsystem->method('checkAccessOfUser')->with(
139  $this->equalTo(6),
140  $this->logicalOr($this->equalTo('read'), $this->equalTo('visible'), $this->equalTo('write')),
141  $this->equalTo('5')
142  )->willReturn(true);
143 
144  $this->setGlobalVariable('rbacsystem', $rbacsystem);
145 
146  $this->assertTrue($this->access::_checkGoto('chtr_5'));
147  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ 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: