Fix tests

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2020-10-12 16:17:08 +02:00
parent 77c59ae4eb
commit c28b08da16
5 changed files with 41 additions and 8 deletions

View File

@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace OCA\Deck\Db; namespace OCA\Deck\Db;
use OCA\Deck\NotFoundException;
use OCA\Deck\Service\CirclesService; use OCA\Deck\Service\CirclesService;
use OCP\AppFramework\Db\Entity; use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\QBMapper; use OCP\AppFramework\Db\QBMapper;
@@ -97,7 +98,7 @@ class AssignedUsersMapper extends QBMapper implements IPermissionMapper {
public function insert(Entity $entity): Entity { public function insert(Entity $entity): Entity {
$origin = $this->getOrigin($entity); $origin = $this->getOrigin($entity);
if ($origin === null) { if ($origin === null) {
throw new \Exception('No origin found for assignment'); throw new NotFoundException('No origin found for assignment');
} }
/** @var AssignedUsers $assignment */ /** @var AssignedUsers $assignment */
$assignment = parent::insert($entity); $assignment = parent::insert($entity);

View File

@@ -23,6 +23,7 @@
namespace OCA\Deck\Db; namespace OCA\Deck\Db;
use OCA\Deck\NotFoundException;
use OCA\Deck\Service\AssignmentService; use OCA\Deck\Service\AssignmentService;
use OCA\Deck\Service\BoardService; use OCA\Deck\Service\BoardService;
use OCA\Deck\Service\StackService; use OCA\Deck\Service\StackService;
@@ -165,8 +166,8 @@ class AssignedUsersMapperTest extends \Test\TestCase {
$assignment->setCardId($this->cards[1]->getId()); $assignment->setCardId($this->cards[1]->getId());
$assignment->setParticipant('invalid-username'); $assignment->setParticipant('invalid-username');
$assignment->setType(AssignedUsers::TYPE_USER); $assignment->setType(AssignedUsers::TYPE_USER);
$actual = $this->assignedUsersMapper->insert($assignment); $this->expectException(NotFoundException::class);
$this->assertNull($actual); $this->assignedUsersMapper->insert($assignment);
} }
/** /**

View File

@@ -31,6 +31,7 @@ class BoardTest extends TestCase {
'acl' => [], 'acl' => [],
'archived' => false, 'archived' => false,
'users' => ['user1', 'user2'], 'users' => ['user1', 'user2'],
'settings' => [],
], $board->jsonSerialize()); ], $board->jsonSerialize());
} }
@@ -50,6 +51,7 @@ class BoardTest extends TestCase {
'acl' => [], 'acl' => [],
'archived' => false, 'archived' => false,
'users' => [], 'users' => [],
'settings' => [],
], $board->jsonSerialize()); ], $board->jsonSerialize());
} }
public function testSetAcl() { public function testSetAcl() {
@@ -77,6 +79,7 @@ class BoardTest extends TestCase {
'archived' => false, 'archived' => false,
'shared' => 1, 'shared' => 1,
'users' => [], 'users' => [],
'settings' => [],
], $board->jsonSerialize()); ], $board->jsonSerialize());
} }
} }

View File

@@ -24,30 +24,38 @@
namespace OCA\Deck\Notification; namespace OCA\Deck\Notification;
use OCA\Deck\Db\Acl; use OCA\Deck\Db\Acl;
use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\Board; use OCA\Deck\Db\Board;
use OCA\Deck\Db\BoardMapper; use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Db\Card; use OCA\Deck\Db\Card;
use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\User; use OCA\Deck\Db\User;
use OCA\Deck\Service\ConfigService;
use OCA\Deck\Service\PermissionService; use OCA\Deck\Service\PermissionService;
use OCP\Comments\IComment; use OCP\Comments\IComment;
use OCP\IConfig;
use OCP\IGroup; use OCP\IGroup;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\IUser; use OCP\IUser;
use OCP\Notification\IManager; use OCP\Notification\IManager;
use OCP\Notification\INotification; use OCP\Notification\INotification;
use PHPUnit\Framework\MockObject\MockObject;
class NotificationHelperTest extends \Test\TestCase { class NotificationHelperTest extends \Test\TestCase {
/** @var CardMapper */ /** @var CardMapper|MockObject */
protected $cardMapper; protected $cardMapper;
/** @var BoardMapper */ /** @var BoardMapper|MockObject */
protected $boardMapper; protected $boardMapper;
/** @var PermissionService */ /** @var AssignedUsersMapper|MockObject */
protected $assignedUsersMapper;
/** @var PermissionService|MockObject */
protected $permissionService; protected $permissionService;
/** @var IManager */ /** @var IConfig|MockObject */
protected $config;
/** @var IManager|MockObject */
protected $notificationManager; protected $notificationManager;
/** @var IGroupManager */ /** @var IGroupManager|MockObject */
protected $groupManager; protected $groupManager;
/** @var string */ /** @var string */
protected $currentUser; protected $currentUser;
@@ -58,14 +66,18 @@ class NotificationHelperTest extends \Test\TestCase {
parent::setUp(); parent::setUp();
$this->cardMapper = $this->createMock(CardMapper::class); $this->cardMapper = $this->createMock(CardMapper::class);
$this->boardMapper = $this->createMock(BoardMapper::class); $this->boardMapper = $this->createMock(BoardMapper::class);
$this->assignedUsersMapper = $this->createMock(AssignedUsersMapper::class);
$this->permissionService = $this->createMock(PermissionService::class); $this->permissionService = $this->createMock(PermissionService::class);
$this->config = $this->createMock(IConfig::class);
$this->notificationManager = $this->createMock(IManager::class); $this->notificationManager = $this->createMock(IManager::class);
$this->groupManager = $this->createMock(IGroupManager::class); $this->groupManager = $this->createMock(IGroupManager::class);
$this->currentUser = 'admin'; $this->currentUser = 'admin';
$this->notificationHelper = new NotificationHelper( $this->notificationHelper = new NotificationHelper(
$this->cardMapper, $this->cardMapper,
$this->boardMapper, $this->boardMapper,
$this->assignedUsersMapper,
$this->permissionService, $this->permissionService,
$this->config,
$this->notificationManager, $this->notificationManager,
$this->groupManager, $this->groupManager,
$this->currentUser $this->currentUser
@@ -90,6 +102,19 @@ class NotificationHelperTest extends \Test\TestCase {
} }
public function testSendCardDuedate() { 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 = $this->createMock(Card::class);
$card->expects($this->at(0)) $card->expects($this->at(0))
->method('__call') ->method('__call')

View File

@@ -36,6 +36,7 @@ use OCA\Deck\Db\LabelMapper;
use OCA\Deck\Db\StackMapper; use OCA\Deck\Db\StackMapper;
use OCA\Deck\NoPermissionException; use OCA\Deck\NoPermissionException;
use OCA\Deck\Notification\NotificationHelper; use OCA\Deck\Notification\NotificationHelper;
use OCP\IConfig;
use OCP\IUser; use OCP\IUser;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IGroupManager; use OCP\IGroupManager;
@@ -80,6 +81,7 @@ class BoardServiceTest extends TestCase {
$this->aclMapper = $this->createMock(AclMapper::class); $this->aclMapper = $this->createMock(AclMapper::class);
$this->boardMapper = $this->createMock(BoardMapper::class); $this->boardMapper = $this->createMock(BoardMapper::class);
$this->stackMapper = $this->createMock(StackMapper::class); $this->stackMapper = $this->createMock(StackMapper::class);
$this->config = $this->createMock(IConfig::class);
$this->labelMapper = $this->createMock(LabelMapper::class); $this->labelMapper = $this->createMock(LabelMapper::class);
$this->permissionService = $this->createMock(PermissionService::class); $this->permissionService = $this->createMock(PermissionService::class);
$this->notificationHelper = $this->createMock(NotificationHelper::class); $this->notificationHelper = $this->createMock(NotificationHelper::class);
@@ -93,6 +95,7 @@ class BoardServiceTest extends TestCase {
$this->service = new BoardService( $this->service = new BoardService(
$this->boardMapper, $this->boardMapper,
$this->stackMapper, $this->stackMapper,
$this->config,
$this->l10n, $this->l10n,
$this->labelMapper, $this->labelMapper,
$this->aclMapper, $this->aclMapper,