diff --git a/lib/Controller/AttachmentApiController.php b/lib/Controller/AttachmentApiController.php new file mode 100644 index 000000000..ee34c4d0d --- /dev/null +++ b/lib/Controller/AttachmentApiController.php @@ -0,0 +1,46 @@ + + * + * @author Ryan Fletcher + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ +namespace OCA\Deck\Controller; + +use OCP\AppFramework\ApiController; +use OCP\AppFramework\Http; +use OCP\AppFramework\Http\DataResponse; +use OCP\IRequest; + +class AttachmentApiController extends ApiController { + public function __construct($appName, IRequest $request) { + parent::__construct($appName, $request); + } + + public function getAll() {} + + public function display() {} + + public function create() {} + + public function update() {} + + public function delete() {} + + public function restore() {} +} \ No newline at end of file diff --git a/tests/unit/controller/AttachmentApiControllerTest.php b/tests/unit/controller/AttachmentApiControllerTest.php new file mode 100644 index 000000000..cedce2563 --- /dev/null +++ b/tests/unit/controller/AttachmentApiControllerTest.php @@ -0,0 +1,165 @@ + + * + * @author Ryan Fletcher + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ +namespace OCA\Deck\Controller; + +use OCP\AppFramework\Http; +use OCP\AppFramework\Http\DataResponse; +use OCP\IRequest; + +use OCA\Deck\Service\AttachmentService; +use OCA\Deck\Db\Attachment; + +class AttachmentApiControllerTest extends \Test\TestCase { + + private $appName = 'deck'; + private $controller; + private $request; + private $attachmentExample; + private $cardId; + private $attachmentService; + + public function setUp() { + parent::setUp(); + $this->attachmentExample = new Attachment(); + $this->attachmentExample->setId(1); + $this->cardId = 1; + $this->request = $this->createMock(IRequest::class); + $this->attachmentService = $this->createMock(AttachmentService::class); + $this->controller = new AttachmentApiController( + $this->appName, + $this->request + ); + } + + public function testGetAll() { + + $allAttachments = [$this->attachmentExample]; + + $this->attachmentService->expects($this->once()) + ->method('findAll') + ->willReturn($allAttachments); + + $this->request->expects($this->once()) + ->method('getParam') + ->with('cardId') + ->willReturn($allAttachments); + + $expected = new DataResponse($this->attachmentExample, HTTP::STATUS_OK); + $actual = $this->controller->getAll(); + $this->assertEquals($expected, $actual); + } + + public function testDisplay() { + + $this->attachmentService->expects($this->once()) + ->method('display') + ->willReturn($this->attachmentExample); + + $this->request->expects($this->exactly(2)) + ->method('getParam') + ->withConsecutive( + ['cardId'], + ['attachmentId'] + )->willReturnonConsecutiveCalls( + $this->cardId, + $this->attachmentExample->getId()); + + $expected = new DataResponse($this->attachmentExample, HTTP::STATUS_OK); + $actual = $this->controller->display(); + $this->assertEquals($expected, $actual); + } + + public function testCreate() { + + $this->attachmentService->expects($this->once()) + ->method('create') + ->willReturn($this->attachmentExample); + + $this->request->expects($this->once()) + ->method('getParam') + ->with('cardId') + ->willReturn($this->cardId); + + $expected = new DataResponse($this->attachmentExample, HTTP::STATUS_OK); + $actual = $this->controller->create(); + $this->assertEquals($expected, $actual); + } + + public function testUpdate() { + + $this->attachmentService->expects($this->once()) + ->method('update') + ->willReturn($this->attachmentExample); + + $this->request->expects($this->exactly(2)) + ->method('getParam') + ->withConsecutive( + ['cardId'], + ['attachmentId'] + )->willReturnonConsecutiveCalls( + $this->cardId, + $this->attachmentExample->getId()); + + $expected = new DataResponse($this->attachmentExample, HTTP::STATUS_OK); + $actual = $this->controller->update(); + $this->assertEquals($expected, $actual); + } + + public function testDelete() { + $this->attachmentService->expects($this->once()) + ->method('delete') + ->willReturn($this->attachmentExample); + + $this->request->expects($this->exactly(2)) + ->method('getParam') + ->withConsecutive( + ['cardId'], + ['attachmentId'] + )->willReturnonConsecutiveCalls( + $this->cardId, + $this->attachmentExample->getId()); + + $expected = new DataResponse($this->attachmentExample, HTTP::STATUS_OK); + $actual = $this->controller->delete(); + $this->assertEquals($expected, $actual); + } + + public function testRestore() { + $this->attachmentService->expects($this->once()) + ->method('restore') + ->willReturn($this->attachmentExample); + + $this->request->expects($this->exactly(2)) + ->method('getParam') + ->withConsecutive( + ['cardId'], + ['attachmentId'] + )->willReturnonConsecutiveCalls( + $this->cardId, + $this->attachmentExample->getId()); + + $expected = new DataResponse($this->attachmentExample, HTTP::STATUS_OK); + $actual = $this->controller->restore(); + $this->assertEquals($expected, $actual); + } +} \ No newline at end of file