ILIAS  trunk Revision v11.0_alpha-1851-ga8564da6fed
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 212 of file ilObjChatroomAccessTest.php.

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

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

◆ testAccessChecksFail()

ilObjChatroomAccessTest::testAccessChecksFail ( )

Definition at line 153 of file ilObjChatroomAccessTest.php.

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

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

◆ testAccessChecksSucceed()

ilObjChatroomAccessTest::testAccessChecksSucceed ( )

Definition at line 180 of file ilObjChatroomAccessTest.php.

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

180  : void
181  {
182  $userId = 1;
183  $refId = 99;
184  $objId = 6;
185 
186  $user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->onlyMethods(
187  ['getId']
188  )->getMock();
189  $user->expects($this->once())->method('getId')->willReturn($userId);
190 
191  $this->setGlobalVariable('ilUser', $user);
192 
193  $this->db->method('fetchAssoc')->willReturnOnConsecutiveCalls(
194  ['keyword' => 'chat_enabled', 'value' => '0'],
195  null
196  );
197 
198  $rbacsystem = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->onlyMethods(
199  ['checkAccessOfUser']
200  )->getMock();
201  $rbacsystem->expects($this->once())->method('checkAccessOfUser')->with(
202  $this->equalTo($userId),
203  $this->equalTo('write'),
204  $this->equalTo($refId)
205  )->willReturn(true);
206 
207  $this->setGlobalVariable('rbacsystem', $rbacsystem);
208 
209  $this->assertTrue($this->access->_checkAccess('unused', 'write', $refId, $objId));
210  }
$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 function (ilDBStatement $statement) {
70  return $statement->fetchAssoc();
71  });
72 
73  $this->db
74  ->method('query')
75  ->with($this->stringContains("FROM settings WHERE module='chatroom'", false))
76  ->willReturn($chatroomSettings);
77  $this->setGlobalVariable('ilDB', $this->db);
78 
79  $rbacsystem = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->onlyMethods(
80  ['checkAccess', 'checkAccessOfUser']
81  )->getMock();
82  $rbacsystem->method('checkAccess')->with(
83  $this->logicalOr($this->equalTo('read'), $this->equalTo('visible')),
84  $this->equalTo('1')
85  )->willReturn(false);
86  $rbacsystem->method('checkAccessOfUser')->with(
87  $this->equalTo(6),
88  $this->logicalOr($this->equalTo('read'), $this->equalTo('visible')),
89  $this->equalTo('1')
90  )->willReturn(false);
91 
92  $this->setGlobalVariable('rbacsystem', $rbacsystem);
93 
94  $this->assertFalse($this->access::_checkGoto(''));
95  $this->assertFalse($this->access::_checkGoto('chtr'));
96  $this->assertFalse($this->access::_checkGoto('chtr_'));
97  $this->assertFalse($this->access::_checkGoto('chtr_'));
98  $this->assertFalse($this->access::_checkGoto('chtr_test'));
99  $this->assertFalse($this->access::_checkGoto('chtr_1'));
100  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:

◆ testGotoCheckSucceeds()

ilObjChatroomAccessTest::testGotoCheckSucceeds ( )

Definition at line 102 of file ilObjChatroomAccessTest.php.

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

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