diff --git a/tests/unit/controller/AttachmentApiControllerTest.php b/tests/unit/controller/AttachmentApiControllerTest.php deleted file mode 100644 index c92878d6b..000000000 --- a/tests/unit/controller/AttachmentApiControllerTest.php +++ /dev/null @@ -1,148 +0,0 @@ - - * - * @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(): void { - 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, - $this->attachmentService - ); - } - - 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($allAttachments, 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->once()) - ->method('getParam') - ->willReturn($this->attachmentExample->getId()); - - $expected = $this->attachmentExample; - $actual = $this->controller->display(); - $this->assertEquals($expected, $actual); - } - - public function testCreate() { - $type = 'not null'; - $data = ['not null']; - - $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($type, $data); - $this->assertEquals($expected, $actual); - } - - public function testUpdate() { - - // FIXME: what is data supposed to be in this context? - $data = ['not empty data']; - - $this->attachmentService->expects($this->once()) - ->method('update') - ->willReturn($this->attachmentExample); - - $this->request->expects($this->once()) - ->method('getParam') - ->willReturn($this->attachmentExample->getId()); - - $expected = new DataResponse($this->attachmentExample, HTTP::STATUS_OK); - $actual = $this->controller->update($data); - $this->assertEquals($expected, $actual); - } - - public function testDelete() { - $this->attachmentService->expects($this->once()) - ->method('delete') - ->willReturn($this->attachmentExample); - - $this->request->expects($this->once()) - ->method('getParam') - ->willReturn($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->once()) - ->method('getParam') - ->willReturn($this->attachmentExample->getId()); - - $expected = new DataResponse($this->attachmentExample, HTTP::STATUS_OK); - $actual = $this->controller->restore(); - $this->assertEquals($expected, $actual); - } -} diff --git a/tests/unit/controller/AttachmentControllerTest.php b/tests/unit/controller/AttachmentControllerTest.php deleted file mode 100644 index 79b20e63d..000000000 --- a/tests/unit/controller/AttachmentControllerTest.php +++ /dev/null @@ -1,99 +0,0 @@ - - * - * @author Julius Härtl - * - * @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 OCA\Deck\Service\AttachmentService; -use OCP\AppFramework\Controller; -use OCP\IRequest; - -class AttachmentControllerTest extends \Test\TestCase { - - /** @var Controller|\PHPUnit\Framework\MockObject\MockObject */ - private $controller; - /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */ - private $request; - /** @var AttachmentService|\PHPUnit\Framework\MockObject\MockObject */ - private $attachmentService; - /** @var string */ - private $userId = 'user'; - - public function setUp(): void { - $this->request = $this->createMock(IRequest::class); - $this->attachmentService = $this->createMock(AttachmentService::class); - $this->controller = new AttachmentController( - 'deck', - $this->request, - $this->attachmentService - ); - } - - public function testGetAll() { - $this->attachmentService->expects($this->once())->method('findAll')->with(1); - $this->controller->getAll(1); - } - - public function testDisplay() { - $this->attachmentService->expects($this->once())->method('display')->with(2); - $this->controller->display(2); - } - - public function testCreate() { - $this->request->expects($this->exactly(2)) - ->method('getParam') - ->will($this->onConsecutiveCalls('type', 'data')); - $this->attachmentService->expects($this->once()) - ->method('create') - ->with(1, 'type', 'data') - ->willReturn(1); - $this->assertEquals(1, $this->controller->create(1)); - } - - public function testUpdate() { - $this->request->expects($this->exactly(1)) - ->method('getParam') - ->will($this->onConsecutiveCalls('data')); - $this->attachmentService->expects($this->once()) - ->method('update') - ->with(2, 'data') - ->willReturn(1); - $this->assertEquals(1, $this->controller->update(2)); - } - - - public function testDelete() { - $this->attachmentService->expects($this->once()) - ->method('delete') - ->with(234) - ->willReturn(1); - $this->assertEquals(1, $this->controller->delete(234)); - } - - public function testRestore() { - $this->attachmentService->expects($this->once()) - ->method('restore') - ->with(234) - ->willReturn(1); - $this->assertEquals(1, $this->controller->restore(234)); - } -}