Files
deck/tests/unit/controller/CardControllerTest.php
Carl Schwan 5cf486150a refactor: Fix psalm issues
- Add typing for most of the services, controllers and mappers
- Add api doc for mappers
- Use vendor-bin for psalm
- Use attributes for controllers
- Fix upload of attachments

Signed-off-by: Carl Schwan <carl.schwan@nextcloud.com>
2025-09-28 11:49:06 +02:00

130 lines
4.0 KiB
PHP

<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Controller;
use OCA\Deck\Db\Card;
use OCA\Deck\Service\AssignmentService;
use OCA\Deck\Service\CardService;
use OCP\IRequest;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class CardControllerTest extends TestCase {
private CardController $controller;
private IRequest&MockObject $request;
private CardService&MockObject $cardService;
private AssignmentService&MockObject $assignmentService;
private string $userId = 'user';
public function setUp(): void {
$this->request = $this->createMock(IRequest::class);
$this->cardService = $this->createMock(CardService::class);
$this->assignmentService = $this->createMock(AssignmentService::class);
$this->controller = new CardController(
'deck',
$this->request,
$this->cardService,
$this->assignmentService,
$this->userId
);
}
public function testRead() {
$card = $this->createMock(Card::class);
$this->cardService->expects($this->once())
->method('find')
->with(123)
->willReturn($card);
$this->assertEquals($card, $this->controller->read(123));
}
public function testCreate(): void {
$card = $this->createMock(Card::class);
$this->cardService->expects($this->once())
->method('create')
->with('foo', 1, 'text', 3, $this->userId)
->willReturn($card);
$this->assertEquals($card, $this->controller->create('foo', 1, 'text', 3));
}
public function testUpdate(): void {
$card = $this->createMock(Card::class);
$this->cardService->expects($this->once())
->method('update')
->with(1, 'title', 3, 'text', $this->userId, 'foo', 5, '2017-01-01 00:00:00')
->willReturn($card);
$this->assertEquals($card, $this->controller->update(1, 'title', 3, 'text', 5, 'foo', '2017-01-01 00:00:00', null));
}
public function testDelete(): void {
$card = $this->createMock(Card::class);
$this->cardService->expects($this->once())
->method('delete')
->with(123)
->willReturn($card);
$this->assertEquals($card, $this->controller->delete(123));
}
public function testArchive() {
$this->cardService->expects($this->once())->method('archive');
$this->controller->archive(1);
}
public function testUnarchive() {
$this->cardService->expects($this->once())->method('unarchive');
$this->controller->unarchive(1);
}
public function testAssignLabel() {
$this->cardService->expects($this->once())->method('assignLabel');
$this->controller->assignLabel(1, 2);
}
public function testRemoveLabel() {
$this->cardService->expects($this->once())->method('removeLabel');
$this->controller->removeLabel(1, 2);
}
public function testReorder() {
$this->cardService->expects($this->once())->method('reorder');
$this->controller->reorder(1, 2, 3);
}
public function testRename() {
$this->cardService->expects($this->once())->method('rename');
$this->controller->rename(1, 'test');
}
public function testAssignUser() {
$this->assignmentService->expects($this->once())->method('assignUser');
$this->controller->assignUser(1, 'admin');
}
public function testUnssignUser() {
$this->assignmentService->expects($this->once())->method('unassignUser');
$this->controller->unassignUser(1, 'admin');
}
}