From c28b08da16e091da58c342e55b4c83e89bae148a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Mon, 12 Oct 2020 16:17:08 +0200 Subject: [PATCH] Fix tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Db/AssignedUsersMapper.php | 3 +- .../database/AssignedUsersMapperTest.php | 5 +-- tests/unit/Db/BoardTest.php | 3 ++ .../Notification/NotificationHelperTest.php | 35 ++++++++++++++++--- tests/unit/Service/BoardServiceTest.php | 3 ++ 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/lib/Db/AssignedUsersMapper.php b/lib/Db/AssignedUsersMapper.php index f7bc5c085..025570055 100644 --- a/lib/Db/AssignedUsersMapper.php +++ b/lib/Db/AssignedUsersMapper.php @@ -25,6 +25,7 @@ declare(strict_types=1); namespace OCA\Deck\Db; +use OCA\Deck\NotFoundException; use OCA\Deck\Service\CirclesService; use OCP\AppFramework\Db\Entity; use OCP\AppFramework\Db\QBMapper; @@ -97,7 +98,7 @@ class AssignedUsersMapper extends QBMapper implements IPermissionMapper { public function insert(Entity $entity): Entity { $origin = $this->getOrigin($entity); if ($origin === null) { - throw new \Exception('No origin found for assignment'); + throw new NotFoundException('No origin found for assignment'); } /** @var AssignedUsers $assignment */ $assignment = parent::insert($entity); diff --git a/tests/integration/database/AssignedUsersMapperTest.php b/tests/integration/database/AssignedUsersMapperTest.php index 37a709c65..06749117b 100644 --- a/tests/integration/database/AssignedUsersMapperTest.php +++ b/tests/integration/database/AssignedUsersMapperTest.php @@ -23,6 +23,7 @@ namespace OCA\Deck\Db; +use OCA\Deck\NotFoundException; use OCA\Deck\Service\AssignmentService; use OCA\Deck\Service\BoardService; use OCA\Deck\Service\StackService; @@ -165,8 +166,8 @@ class AssignedUsersMapperTest extends \Test\TestCase { $assignment->setCardId($this->cards[1]->getId()); $assignment->setParticipant('invalid-username'); $assignment->setType(AssignedUsers::TYPE_USER); - $actual = $this->assignedUsersMapper->insert($assignment); - $this->assertNull($actual); + $this->expectException(NotFoundException::class); + $this->assignedUsersMapper->insert($assignment); } /** diff --git a/tests/unit/Db/BoardTest.php b/tests/unit/Db/BoardTest.php index 63c7f2b82..369e13a61 100644 --- a/tests/unit/Db/BoardTest.php +++ b/tests/unit/Db/BoardTest.php @@ -31,6 +31,7 @@ class BoardTest extends TestCase { 'acl' => [], 'archived' => false, 'users' => ['user1', 'user2'], + 'settings' => [], ], $board->jsonSerialize()); } @@ -50,6 +51,7 @@ class BoardTest extends TestCase { 'acl' => [], 'archived' => false, 'users' => [], + 'settings' => [], ], $board->jsonSerialize()); } public function testSetAcl() { @@ -77,6 +79,7 @@ class BoardTest extends TestCase { 'archived' => false, 'shared' => 1, 'users' => [], + 'settings' => [], ], $board->jsonSerialize()); } } diff --git a/tests/unit/Notification/NotificationHelperTest.php b/tests/unit/Notification/NotificationHelperTest.php index a1d771da4..dfd320dcd 100644 --- a/tests/unit/Notification/NotificationHelperTest.php +++ b/tests/unit/Notification/NotificationHelperTest.php @@ -24,30 +24,38 @@ namespace OCA\Deck\Notification; use OCA\Deck\Db\Acl; +use OCA\Deck\Db\AssignedUsersMapper; use OCA\Deck\Db\Board; use OCA\Deck\Db\BoardMapper; use OCA\Deck\Db\Card; use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\User; +use OCA\Deck\Service\ConfigService; use OCA\Deck\Service\PermissionService; use OCP\Comments\IComment; +use OCP\IConfig; use OCP\IGroup; use OCP\IGroupManager; use OCP\IUser; use OCP\Notification\IManager; use OCP\Notification\INotification; +use PHPUnit\Framework\MockObject\MockObject; class NotificationHelperTest extends \Test\TestCase { - /** @var CardMapper */ + /** @var CardMapper|MockObject */ protected $cardMapper; - /** @var BoardMapper */ + /** @var BoardMapper|MockObject */ protected $boardMapper; - /** @var PermissionService */ + /** @var AssignedUsersMapper|MockObject */ + protected $assignedUsersMapper; + /** @var PermissionService|MockObject */ protected $permissionService; - /** @var IManager */ + /** @var IConfig|MockObject */ + protected $config; + /** @var IManager|MockObject */ protected $notificationManager; - /** @var IGroupManager */ + /** @var IGroupManager|MockObject */ protected $groupManager; /** @var string */ protected $currentUser; @@ -58,14 +66,18 @@ class NotificationHelperTest extends \Test\TestCase { parent::setUp(); $this->cardMapper = $this->createMock(CardMapper::class); $this->boardMapper = $this->createMock(BoardMapper::class); + $this->assignedUsersMapper = $this->createMock(AssignedUsersMapper::class); $this->permissionService = $this->createMock(PermissionService::class); + $this->config = $this->createMock(IConfig::class); $this->notificationManager = $this->createMock(IManager::class); $this->groupManager = $this->createMock(IGroupManager::class); $this->currentUser = 'admin'; $this->notificationHelper = new NotificationHelper( $this->cardMapper, $this->boardMapper, + $this->assignedUsersMapper, $this->permissionService, + $this->config, $this->notificationManager, $this->groupManager, $this->currentUser @@ -90,6 +102,19 @@ class NotificationHelperTest extends \Test\TestCase { } public function testSendCardDuedate() { + $this->config->expects($this->at(0)) + ->method('getUserValue') + ->with('foo', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED) + ->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ALL); + $this->config->expects($this->at(1)) + ->method('getUserValue') + ->with('bar', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED) + ->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ALL); + $this->config->expects($this->at(2)) + ->method('getUserValue') + ->with('asd', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED) + ->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ALL); + $card = $this->createMock(Card::class); $card->expects($this->at(0)) ->method('__call') diff --git a/tests/unit/Service/BoardServiceTest.php b/tests/unit/Service/BoardServiceTest.php index 6553a6245..ec4920c10 100644 --- a/tests/unit/Service/BoardServiceTest.php +++ b/tests/unit/Service/BoardServiceTest.php @@ -36,6 +36,7 @@ use OCA\Deck\Db\LabelMapper; use OCA\Deck\Db\StackMapper; use OCA\Deck\NoPermissionException; use OCA\Deck\Notification\NotificationHelper; +use OCP\IConfig; use OCP\IUser; use OCP\IUserManager; use OCP\IGroupManager; @@ -80,6 +81,7 @@ class BoardServiceTest extends TestCase { $this->aclMapper = $this->createMock(AclMapper::class); $this->boardMapper = $this->createMock(BoardMapper::class); $this->stackMapper = $this->createMock(StackMapper::class); + $this->config = $this->createMock(IConfig::class); $this->labelMapper = $this->createMock(LabelMapper::class); $this->permissionService = $this->createMock(PermissionService::class); $this->notificationHelper = $this->createMock(NotificationHelper::class); @@ -93,6 +95,7 @@ class BoardServiceTest extends TestCase { $this->service = new BoardService( $this->boardMapper, $this->stackMapper, + $this->config, $this->l10n, $this->labelMapper, $this->aclMapper,