clientApi = new \Box\Mod\Support\Api\Client(); } public function testTicketGetList(): void { $simpleResultArr = [ 'list' => [ ['id' => 1], ], ]; $paginatorMock = $this->getMockBuilder(\FOSSBilling\Pagination::class) ->onlyMethods(['getPaginatedResultSet']) ->disableOriginalConstructor() ->getMock(); $paginatorMock->expects($this->atLeastOnce()) ->method('getPaginatedResultSet') ->willReturn($simpleResultArr); $serviceMock = $this->getMockBuilder(\Box\Mod\Support\Service::class) ->onlyMethods(['getSearchQuery', 'toApiArray'])->getMock(); $serviceMock->expects($this->atLeastOnce())->method('getSearchQuery') ->willReturn(['query', []]); $serviceMock->expects($this->atLeastOnce()) ->method('toApiArray') ->willReturn([]); $model = new \Model_SupportTicket(); $model->loadBean(new \DummyBean()); $dbMock = $this->createMock('\Box_Database'); $dbMock->expects($this->atLeastOnce()) ->method('getExistingModelById') ->willReturn($model); $di = $this->getDi(); $di['pager'] = $paginatorMock; $di['db'] = $dbMock; $this->clientApi->setDi($di); $client = new \Model_Client(); $client->loadBean(new \DummyBean()); $client->id = 1; $this->clientApi->setService($serviceMock); $this->clientApi->setIdentity($client); $data = []; $result = $this->clientApi->ticket_get_list($data); $this->assertIsArray($result); } public function testTicketGet(): void { $serviceMock = $this->getMockBuilder(\Box\Mod\Support\Service::class) ->onlyMethods(['findOneByClient', 'toApiArray'])->getMock(); $serviceMock->expects($this->atLeastOnce())->method('findOneByClient') ->willReturn(new \Model_SupportTicket()); $serviceMock->expects($this->atLeastOnce())->method('toApiArray') ->willReturn([]); $di = $this->getDi(); $this->clientApi->setDi($di); $client = new \Model_Client(); $client->loadBean(new \DummyBean()); $client->id = 1; $this->clientApi->setService($serviceMock); $this->clientApi->setIdentity($client); $data = [ 'id' => 1, ]; $result = $this->clientApi->ticket_get($data); $this->assertIsArray($result); } public function testHelpdeskGetPairs(): void { $serviceMock = $this->getMockBuilder(\Box\Mod\Support\Service::class) ->onlyMethods(['helpdeskGetPairs'])->getMock(); $serviceMock->expects($this->atLeastOnce())->method('helpdeskGetPairs') ->willReturn([0 => 'General']); $this->clientApi->setService($serviceMock); $result = $this->clientApi->helpdesk_get_pairs(); $this->assertIsArray($result); } public function testTicketCreate(): void { $serviceMock = $this->getMockBuilder(\Box\Mod\Support\Service::class) ->onlyMethods(['ticketCreateForClient'])->getMock(); $serviceMock->expects($this->atLeastOnce())->method('ticketCreateForClient') ->willReturn(1); $dbMock = $this->getMockBuilder('\Box_Database')->disableOriginalConstructor()->getMock(); $dbMock->expects($this->atLeastOnce()) ->method('getExistingModelById') ->willReturn(new \Model_SupportHelpdesk()); $di = $this->getDi(); $di['db'] = $dbMock; $this->clientApi->setDi($di); $client = new \Model_Client(); $client->loadBean(new \DummyBean()); $client->id = 1; $this->clientApi->setService($serviceMock); $this->clientApi->setIdentity($client); $data = [ 'content' => 'Content', 'subject' => 'Subject', 'support_helpdesk_id' => 1, ]; $result = $this->clientApi->ticket_create($data); $this->assertIsInt($result); } public function testTicketReply(): void { $serviceMock = $this->getMockBuilder(\Box\Mod\Support\Service::class) ->onlyMethods(['canBeReopened', 'ticketReply'])->getMock(); $serviceMock->expects($this->atLeastOnce())->method('canBeReopened') ->willReturn(true); $serviceMock->expects($this->atLeastOnce())->method('ticketReply') ->willReturn(1); $dbMock = $this->getMockBuilder('\Box_Database')->disableOriginalConstructor()->getMock(); $dbMock->expects($this->atLeastOnce()) ->method('findOne') ->willReturn(new \Model_SupportTicket()); $di = $this->getDi(); $di['db'] = $dbMock; $this->clientApi->setDi($di); $client = new \Model_Client(); $client->loadBean(new \DummyBean()); $client->id = 1; $this->clientApi->setService($serviceMock); $this->clientApi->setIdentity($client); $data = [ 'content' => 'Content', 'id' => 1, ]; $result = $this->clientApi->ticket_reply($data); $this->assertIsBool($result); $this->assertTrue($result); } public function testTicketReplyCanNotBeReopenedException(): void { $serviceMock = $this->getMockBuilder(\Box\Mod\Support\Service::class) ->onlyMethods(['canBeReopened', 'ticketReply'])->getMock(); $serviceMock->expects($this->atLeastOnce())->method('canBeReopened') ->willReturn(false); $serviceMock->expects($this->never())->method('ticketReply') ->willReturn(1); $dbMock = $this->getMockBuilder('\Box_Database')->disableOriginalConstructor()->getMock(); $dbMock->expects($this->atLeastOnce()) ->method('findOne') ->willReturn(new \Model_SupportTicket()); $di = $this->getDi(); $di['db'] = $dbMock; $this->clientApi->setDi($di); $client = new \Model_Client(); $client->loadBean(new \DummyBean()); $client->id = 1; $this->clientApi->setService($serviceMock); $this->clientApi->setIdentity($client); $data = [ 'content' => 'Content', 'id' => 1, ]; $this->expectException(\FOSSBilling\Exception::class); $result = $this->clientApi->ticket_reply($data); $this->assertIsInt($result); } public function testTicketClose(): void { $serviceMock = $this->getMockBuilder(\Box\Mod\Support\Service::class) ->onlyMethods(['findOneByClient', 'closeTicket'])->getMock(); $serviceMock->expects($this->atLeastOnce())->method('findOneByClient') ->willReturn(new \Model_SupportTicket()); $serviceMock->expects($this->atLeastOnce())->method('closeTicket') ->willReturn(true); $di = $this->getDi(); $this->clientApi->setDi($di); $client = new \Model_Client(); $client->loadBean(new \DummyBean()); $client->id = 1; $this->clientApi->setService($serviceMock); $this->clientApi->setIdentity($client); $data = [ 'content' => 'Content', 'id' => 1, ]; $result = $this->clientApi->ticket_close($data); $this->assertTrue($result); } }