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;
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);

View File

@@ -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);
}
/**

View File

@@ -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());
}
}

View File

@@ -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')

View File

@@ -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,