ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilChatroomClearTaskTest.php
Go to the documentation of this file.
1<?php
2
3require_once dirname(__FILE__) . '/../class.ilChatroomAbstractTaskTest.php';
4
10{
11
15 protected $task;
16
17 protected function setUp()
18 {
19 parent::setUp();
20
21 require_once './Modules/Chatroom/classes/gui/class.ilChatroomClearGUI.php';
22 require_once './Modules/Chatroom/classes/class.ilChatroomServerSettings.php';
23
24 $settings = new ilChatroomServerSettings();
25
30 $this->createilChatroomMock();
32 $this->createIlChatroomServerConnectorFileGetContentsMock(array('success' => true));
33 $this->createIlObjChatroomMock(15);
34 $this->createIlObjChatroomGUIMock($this->object);
36
37 $this->task = $this->createMock(
38 'ilChatroomClearGUI',
39 array('sendResponse', 'getRoomByObjectId', 'redirectIfNoPermission'),
40 array($this->gui)
41 );
42 }
43
44 public function testExecuteDefault()
45 {
46 $_REQUEST['sub'] = 0;
47
48 $this->task->expects($this->once())->method('redirectIfNoPermission')->with(
49 $this->equalTo('moderate')
50 );
51 $this->task->expects($this->any())->method('getRoomByObjectId')->will(
52 $this->returnValue($this->ilChatroomMock)
53 );
54 $this->createSendResponseMock($this->task, array(
55 'success' => true,
56 ));
57
58 $this->setExpectedException('Exception', 'Exit', 0);
59 $this->task->executeDefault(null);
60 }
61
63 {
64 $_REQUEST['sub'] = 0;
65
66 $this->task->expects($this->once())->method('redirectIfNoPermission')->with('moderate')->will($this->returnCallback(function () {
67 throw new Exception('Weak redirect on no Permission. Send just failure message instead', 1456351768);
68 }));
69
70 $this->setExpectedException('Exception', "", 1456351768);
71 $this->task->executeDefault(null);
72 }
73
75 {
76 $_REQUEST['sub'] = 0;
77
78 $this->task->expects($this->once())->method('redirectIfNoPermission')->with(
79 $this->equalTo('moderate')
80 );
81 $this->task->expects($this->any())->method('getRoomByObjectId')->will(
82 $this->returnValue(null)
83 );
84 $this->createSendResponseMock($this->task, array(
85 'success' => false,
86 'reason' => 'unkown room',
87 ));
88
89 $this->setExpectedException('Exception', 'Exit', 0);
90 $this->task->executeDefault(null);
91 }
92}
An exception for terminatinating execution or to throw for unit testing.
Class ilChatroomAbstractTaskTest.
Class ilChatroomServerConnectorMock.
Class ilChatroomServerSettings.
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.