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

87 lines
2.4 KiB
PHP

<?php
namespace OCA\UPschooling\Tests\Unit\Controller;
use OCA\UPschooling\Controller\TicketApiController;
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;
use Psr\Log\NullLogger;
class TicketApiControllerTest extends TestCase
{
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();
$this->ticketService = $this->getMockBuilder(TicketService::class)
->disableOriginalConstructor()
->getMock();
$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,
);
}
public function testCreate()
{
$title = 'title here';
$content = 'just check if this value is returned correctly';
$ticketId = 1;
$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(),
));
$response = $this->controller->create($title, $content);
$responseData = $response->getData();
$this->assertEquals($ticketId, $responseData['ticketId']);
}
/*
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());
}*/
}