2021-08-21 14:17:14 +00:00
|
|
|
<?php
|
|
|
|
|
2021-08-21 14:25:23 +00:00
|
|
|
namespace OCA\UPschooling\Tests\Unit\Controller;
|
2021-08-21 14:17:14 +00:00
|
|
|
|
2021-08-22 15:02:03 +00:00
|
|
|
use OCA\UPschooling\Controller\TicketApiController;
|
2021-09-18 17:28:10 +00:00
|
|
|
use OCA\UPschooling\Service\NoteNotFound;
|
|
|
|
use OCA\UPschooling\Service\TicketService;
|
|
|
|
use OCP\AppFramework\Http;
|
|
|
|
use OCP\IRequest;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2021-08-21 14:17:14 +00:00
|
|
|
|
2021-09-18 17:28:10 +00:00
|
|
|
class NoteApiControllerTest extends TestCase
|
|
|
|
{
|
|
|
|
protected $controller;
|
|
|
|
protected $service;
|
|
|
|
protected $userId = 'john';
|
|
|
|
protected $request;
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
$this->request = $this->getMockBuilder(IRequest::class)->getMock();
|
|
|
|
$this->service = $this->getMockBuilder(TicketService::class)
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2021-08-22 15:02:03 +00:00
|
|
|
$this->controller = new TicketApiController($this->request, $this->service, $this->userId);
|
2021-08-21 14:17:14 +00:00
|
|
|
}
|
2021-09-18 17:28:10 +00:00
|
|
|
|
|
|
|
public function testUpdate()
|
|
|
|
{
|
|
|
|
$note = 'just check if this value is returned correctly';
|
|
|
|
$this->service->expects($this->once())
|
|
|
|
->method('update')
|
|
|
|
->with($this->equalTo(3),
|
|
|
|
$this->equalTo('title'),
|
|
|
|
$this->equalTo('content'),
|
|
|
|
$this->equalTo($this->userId))
|
|
|
|
->will($this->returnValue($note));
|
|
|
|
|
2021-10-10 17:49:36 +00:00
|
|
|
$result = $this->controller->update(3);
|
2021-09-18 17:28:10 +00:00
|
|
|
|
|
|
|
$this->assertEquals($note, $result->getData());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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()));
|
|
|
|
|
2021-10-10 17:49:36 +00:00
|
|
|
$result = $this->controller->update(3);
|
2021-09-18 17:28:10 +00:00
|
|
|
|
|
|
|
$this->assertEquals(Http::STATUS_NOT_FOUND, $result->getStatus());
|
|
|
|
}
|
2021-08-21 14:17:14 +00:00
|
|
|
}
|