Nextcloud-App/tests/Unit/Controller/TicketApiControllerTest.php

87 lines
2.4 KiB
PHP
Raw Normal View History

<?php
2021-08-21 14:25:23 +00:00
namespace OCA\UPschooling\Tests\Unit\Controller;
2021-08-22 15:02:03 +00:00
use OCA\UPschooling\Controller\TicketApiController;
2023-10-11 19:55:03 +00:00
use OCA\UPschooling\Db\TicketMapper;
use OCA\UPschooling\Service\ChatService;
use OCA\UPschooling\Service\MatrixService;
use OCA\UPschooling\Service\TicketService;
use OCP\IRequest;
use PHPUnit\Framework\TestCase;
2023-10-11 19:55:03 +00:00
use Psr\Log\NullLogger;
2021-10-10 17:51:12 +00:00
class TicketApiControllerTest extends TestCase
{
2023-10-11 19:55:03 +00:00
protected TicketApiController $controller;
protected string $userId = 'john';
protected TicketService $ticketService;
protected TicketMapper $ticketMapper;
protected MatrixService $matrixService;
protected ChatService $chatService;
protected IRequest $request;
public function setUp(): void
{
$this->request = $this->getMockBuilder(IRequest::class)->getMock();
2023-10-11 19:55:03 +00:00
$this->ticketService = $this->getMockBuilder(TicketService::class)
->disableOriginalConstructor()
->getMock();
2023-10-11 19:55:03 +00:00
$this->ticketMapper = $this->getMockBuilder(TicketMapper::class)
->disableOriginalConstructor()
->getMock();
$this->matrixService = $this->getMockBuilder(MatrixService::class)
->disableOriginalConstructor()
->getMock();
$this->chatService = $this->getMockBuilder(ChatService::class)
->disableOriginalConstructor()
->getMock();
$this->controller = new TicketApiController(
$this->request,
new NullLogger(),
$this->ticketService,
$this->ticketMapper,
$this->matrixService,
$this->chatService,
$this->userId,
);
}
2023-10-11 19:55:03 +00:00
public function testCreate()
{
2023-10-11 19:55:03 +00:00
$title = 'title here';
$content = 'just check if this value is returned correctly';
$ticketId = 1;
2023-10-11 19:55:03 +00:00
$this->ticketService->expects($this->once())
->method('create')
->with($this->equalTo($title), $this->equalTo($content), $this->equalTo($this->userId))
->willReturn(array(
'ticketId' => $ticketId,
'status' => "open",
'lastModified' => $this->any(),
'title' => $title,
'description' => $content,
'matrixHelperName' => null,
'expirationDate' => $this->any(),
));
2023-10-11 19:55:03 +00:00
$response = $this->controller->create($title, $content);
$responseData = $response->getData();
$this->assertEquals($ticketId, $responseData['ticketId']);
}
2021-10-10 17:51:12 +00:00
/*
public function testUpdateNotFound()
{
// test the correct status code if no note is found
$this->service->expects($this->once())
->method('update')
->will($this->throwException(new NoteNotFound()));
$result = $this->controller->update(3);
$this->assertEquals(Http::STATUS_NOT_FOUND, $result->getStatus());
2021-10-10 17:51:12 +00:00
}*/
}