ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilObjChatroomAccessTest.php
Go to the documentation of this file.
1 <?php
2 
8 {
9 
13  protected $access;
14 
15  protected function setUp()
16  {
17  if (defined('ILIAS_PHPUNIT_CONTEXT')) {
18  include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
19  ilUnitUtil::performInitialisation();
20  } else {
21  chdir(dirname(__FILE__));
22  chdir('../../../');
23  }
24 
25  require_once './Services/Administration/classes/class.ilSetting.php';
26  require_once './Modules/Chatroom/classes/class.ilObjChatroomAccess.php';
27  $this->access = new ilObjChatroomAccess();
28  }
29 
30  public function testInstanceOf()
31  {
32  $this->assertInstanceOf('ilObjectAccess', $this->access);
33  }
34 
35  public function test_getCommands()
36  {
37  $expected = array(
38  array("permission" => "read", "cmd" => "view", "lang_var" => "enter", "default" => true),
39  array("permission" => "write", "cmd" => "settings-general", "lang_var" => "settings"),
40  );
41 
42  $commands = $this->access->_getCommands();
43 
44  $this->assertInternalType("array", $commands);
45  $this->assertEquals($expected, $commands);
46  }
47 
48  public function test_checkGotoReturnFalse()
49  {
50  $GLOBALS['rbacsystem'] = $this->getMockBuilder('ilRbacSystem')->disableOriginalConstructor()->setMethods(
51  array('checkAccess',)
52  )->getMock();
53  $GLOBALS['rbacsystem']->expects($this->any())->method('checkAccess')->with(
54  $this->equalTo('read'),
55  $this->equalTo('1')
56  )->will($this->returnValue(false));
57 
58  $this->assertFalse($this->access->_checkGoto(''));
59  $this->assertFalse($this->access->_checkGoto('chtr'));
60  $this->assertFalse($this->access->_checkGoto('chtr_'));
61  $this->assertFalse($this->access->_checkGoto('chtr_'));
62  $this->assertFalse($this->access->_checkGoto('chtr_test'));
63  $this->assertFalse($this->access->_checkGoto('chtr_1'));
64  }
65 
66  public function test_checkGotoReturnTrue()
67  {
68  $GLOBALS['rbacsystem'] = $this->getMockBuilder('ilRbacSystem')->disableOriginalConstructor()->setMethods(
69  array('checkAccess')
70  )->getMock();
71  $GLOBALS['rbacsystem']->expects($this->once())->method('checkAccess')->with(
72  $this->equalTo('read'),
73  $this->equalTo('5')
74  )->will($this->returnValue(true));
75  $this->assertTrue($this->access->_checkGoto('chtr_5'));
76  }
77 
79  {
80  $this->assertFalse($this->access->_checkGoto(array('chtr', '5')));
81  $this->assertFalse($this->access->_checkGoto(5));
82  }
83 
84  public function test_checkAccessReturnFalse()
85  {
86  $userId = 1;
87  $refId = 99;
88  $GLOBALS['ilUser'] = $this->getMockBuilder('ilUser')->disableOriginalConstructor()->setMethods(
89  array('getId')
90  )->getMock();
91  $GLOBALS['ilUser']->expects($this->once())->method('getId')->will($this->returnValue($userId));
92 
93  $GLOBALS['ilDB'] = $this->getMockBuilder('ilDBMySQL')->disableOriginalConstructor()->setMethods(
94  array('quote', 'query', 'fetchAssoc')
95  )->getMock();
96  $GLOBALS['ilDB']->expects($this->any())->method('quote');
97  $GLOBALS['ilDB']->expects($this->any())->method('query');
98  $GLOBALS['ilDB']->expects($this->at(0))->method('fetchAssoc')->will(
99  $this->returnValue(array('keyword' => 'chat_enabled', 'value' => false))
100  );
101 
102  $GLOBALS['rbacsystem'] = $this->getMockBuilder('ilRbacSystem')->disableOriginalConstructor()->setMethods(
103  array('checkAccessOfUser')
104  )->getMock();
105  $GLOBALS['rbacsystem']->expects($this->once())->method('checkAccessOfUser')->with(
106  $this->equalTo($userId),
107  $this->equalTo('write'),
108  $this->equalTo($refId)
109  )->will($this->returnValue(false));
110 
111  $this->assertFalse($this->access->_checkAccess('unused', 'unused', $refId, 'unused'));
112  }
113 
115  {
116  $userId = 1;
117  $refId = 99;
118  $GLOBALS['ilUser'] = $this->getMockBuilder('ilUser')->disableOriginalConstructor()->setMethods(
119  array('getId')
120  )->getMock();
121  $GLOBALS['ilUser']->expects($this->once())->method('getId')->will($this->returnValue($userId));
122 
123  $GLOBALS['ilDB'] = $this->getMockBuilder('ilDBMySQL')->disableOriginalConstructor()->setMethods(
124  array('quote', 'query', 'fetchAssoc')
125  )->getMock();
126  $GLOBALS['ilDB']->expects($this->any())->method('quote');
127  $GLOBALS['ilDB']->expects($this->any())->method('query');
128  $GLOBALS['ilDB']->expects($this->any())->method('fetchAssoc')->will(
129  $this->returnValue(array('keyword' => 'chat_enabled', 'value' => false))
130  );
131 
132  $GLOBALS['rbacsystem'] = $this->getMockBuilder('ilRbacSystem')->disableOriginalConstructor()->setMethods(
133  array('checkAccessOfUser')
134  )->getMock();
135  $GLOBALS['rbacsystem']->expects($this->once())->method('checkAccessOfUser')->with(
136  $this->equalTo($userId),
137  $this->equalTo('write'),
138  $this->equalTo($refId)
139  )->will($this->returnValue(true));
140 
141  $this->assertTrue($this->access->_checkAccess('unused', 'unused', $refId, 'unused'));
142  }
143 }
Access class for chatroom objects.
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
Class ilObjChatroomAccessTest.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.