Example #1
0
 public function testTicket_create()
 {
     $validatorMock = $this->getMockBuilder('\\Box_Validate')->disableOriginalConstructor()->getMock();
     $validatorMock->expects($this->atLeastOnce())->method('checkRequiredParamsForArray')->will($this->returnValue(null));
     $clientModel = new \Model_Client();
     $clientModel->loadBean(new \RedBeanPHP\OODBBean());
     $supportHelpdeskModel = new \Model_SupportHelpdesk();
     $supportHelpdeskModel->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock = $this->getMockBuilder('\\Box_Database')->disableOriginalConstructor()->getMock();
     $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->onConsecutiveCalls($clientModel, $supportHelpdeskModel));
     $randID = rand(1, 100);
     $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Support\\Service')->getMock();
     $serviceMock->expects($this->atLeastOnce())->method('ticketCreateForAdmin')->will($this->returnValue($randID));
     $di = new \Box_Di();
     $di['validator'] = $validatorMock;
     $di['db'] = $dbMock;
     $this->adminApi->setDi($di);
     $this->adminApi->setService($serviceMock);
     $this->adminApi->setIdentity(new \Model_Admin());
     $data = array('client_id' => rand(1, 100), 'content' => 'Content', 'subject' => 'Subject', 'support_helpdesk_id' => rand(1, 100));
     $result = $this->adminApi->ticket_create($data);
     $this->assertInternalType('integer', $result);
     $this->assertEquals($randID, $result);
 }
Example #2
0
 public function testCannedCreate()
 {
     $randId = rand(1, 100);
     $helpDeskModel = new \Model_SupportHelpdesk();
     $helpDeskModel->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock = $this->getMockBuilder('\\Box_Database')->disableOriginalConstructor()->getMock();
     $dbMock->expects($this->atLeastOnce())->method('dispense')->will($this->returnValue($helpDeskModel));
     $dbMock->expects($this->atLeastOnce())->method('store')->will($this->returnValue($randId));
     $settingsServiceMock = $this->getMockBuilder('\\Box\\Mod\\Email\\Service')->setMethods(array('checkLimits'))->getMock();
     $settingsServiceMock->expects($this->atLeastOnce())->method('checkLimits')->will($this->returnValue(null));
     $di = new \Box_Di();
     $di['mod_service'] = $di->protect(function () use($settingsServiceMock) {
         return $settingsServiceMock;
     });
     $di['db'] = $dbMock;
     $di['logger'] = $this->getMockBuilder('Box_Log')->getMock();
     $this->service->setDi($di);
     $ticket = new \Model_SupportHelpdesk();
     $ticket->loadBean(new \RedBeanPHP\OODBBean());
     $data = array('name' => 'Name', 'email' => 'email@example.com', 'can_reopen' => 1, 'close_after' => rand(1, 100), 'signature' => 'Signature');
     $result = $this->service->cannedCreate($data, rand(1, 100), 'Content');
     $this->assertInternalType('integer', $result);
     $this->assertEquals($result, $randId);
 }
Example #3
0
 public function testonAfterClientOpenTicket_mod_support_helpdesk_ticket_open()
 {
     $di = new \Box_Di();
     $ticketModel = new \Model_SupportTicket();
     $ticketModel->loadBean(new \RedBeanPHP\OODBBean());
     $supportServiceMock = $this->getMockBuilder('\\Box\\Mod\\Support\\Service')->getMock();
     $supportServiceMock->expects($this->atLeastOnce())->method('getTicketById')->will($this->returnValue($ticketModel));
     $supportTicketArray = array();
     $supportServiceMock->expects($this->atLeastOnce())->method('toApiArray')->willReturn($supportTicketArray);
     $helpdeskModel = new \Model_SupportHelpdesk();
     $helpdeskModel->loadBean(new \RedBeanPHP\OODBBean());
     $helpdeskModel->email = 'helpdesk@support.com';
     $emailServiceMock = $this->getMockBuilder('\\Box\\Mod\\Email\\Service')->getMock();
     $emailConfig = array('to' => $helpdeskModel->email, 'code' => 'mod_support_helpdesk_ticket_open', 'ticket' => $supportTicketArray);
     $emailServiceMock->expects($this->once())->method('sendTemplate')->with($emailConfig)->willReturn(true);
     $di['mod_service'] = $di->protect(function ($name) use($supportServiceMock, $emailServiceMock) {
         if ($name == 'support') {
             return $supportServiceMock;
         }
         if ($name == 'email') {
             return $emailServiceMock;
         }
     });
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('load')->willReturn($helpdeskModel);
     $di['db'] = $dbMock;
     $di['loggedin_admin'] = new \Model_Admin();
     $eventMock = $this->getMockBuilder('\\Box_Event')->disableOriginalConstructor()->getMock();
     $eventMock->expects($this->atLeastOnce())->method('getDi')->willReturn($di);
     $eventMock->expects($this->atLeastOnce())->method('getparameters');
     $service = new \Box\Mod\Staff\Service();
     $service->onAfterClientOpenTicket($eventMock);
 }