Fix existing service tests

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2018-09-06 09:25:50 +02:00
parent e06a5ad44f
commit eea5803ae5
4 changed files with 62 additions and 27 deletions

View File

@@ -112,7 +112,7 @@ class AttachmentServiceTest extends TestCase {
$application->expects($this->any()) $application->expects($this->any())
->method('getContainer') ->method('getContainer')
->willReturn($appContainer); ->willReturn($appContainer);
$attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->permissionService, $application, $this->cacheFactory, $this->userId, $this->l10n); $attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->permissionService, $application, $this->cacheFactory, $this->userId, $this->l10n, $this->activityManager);
$attachmentService->registerAttachmentService('custom', MyAttachmentService::class); $attachmentService->registerAttachmentService('custom', MyAttachmentService::class);
$this->assertEquals($fileServiceMock, $attachmentService->getService('deck_file')); $this->assertEquals($fileServiceMock, $attachmentService->getService('deck_file'));
$this->assertEquals(MyAttachmentService::class, get_class($attachmentService->getService('custom'))); $this->assertEquals(MyAttachmentService::class, get_class($attachmentService->getService('custom')));
@@ -130,7 +130,7 @@ class AttachmentServiceTest extends TestCase {
$application->expects($this->any()) $application->expects($this->any())
->method('getContainer') ->method('getContainer')
->willReturn($appContainer); ->willReturn($appContainer);
$attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->permissionService, $application, $this->cacheFactory, $this->userId, $this->l10n); $attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->permissionService, $application, $this->cacheFactory, $this->userId, $this->l10n, $this->activityManager);
$attachmentService->registerAttachmentService('custom', MyAttachmentService::class); $attachmentService->registerAttachmentService('custom', MyAttachmentService::class);
$attachmentService->getService('deck_file_invalid'); $attachmentService->getService('deck_file_invalid');
} }

View File

@@ -24,6 +24,7 @@
namespace OCA\Deck\Service; namespace OCA\Deck\Service;
use OC\L10N\L10N; use OC\L10N\L10N;
use OCA\Deck\Activity\ActivityManager;
use OCA\Deck\Db\Acl; use OCA\Deck\Db\Acl;
use OCA\Deck\Db\AclMapper; use OCA\Deck\Db\AclMapper;
use OCA\Deck\Db\AssignedUsers; use OCA\Deck\Db\AssignedUsers;
@@ -59,6 +60,8 @@ class BoardServiceTest extends TestCase {
private $userManager; private $userManager;
/** @var IUserManager */ /** @var IUserManager */
private $groupManager; private $groupManager;
/** @var ActivityManager */
private $activityManager;
private $userId = 'admin'; private $userId = 'admin';
@@ -73,6 +76,7 @@ class BoardServiceTest extends TestCase {
$this->assignedUsersMapper = $this->createMock(AssignedUsersMapper::class); $this->assignedUsersMapper = $this->createMock(AssignedUsersMapper::class);
$this->userManager = $this->createMock(IUserManager::class); $this->userManager = $this->createMock(IUserManager::class);
$this->groupManager = $this->createMock(IGroupManager::class); $this->groupManager = $this->createMock(IGroupManager::class);
$this->activityManager = $this->createMock(ActivityManager::class);
$this->service = new BoardService( $this->service = new BoardService(
$this->boardMapper, $this->boardMapper,
@@ -84,6 +88,7 @@ class BoardServiceTest extends TestCase {
$this->assignedUsersMapper, $this->assignedUsersMapper,
$this->userManager, $this->userManager,
$this->groupManager, $this->groupManager,
$this->activityManager,
$this->userId $this->userId
); );
@@ -186,7 +191,12 @@ class BoardServiceTest extends TestCase {
->willReturn([ ->willReturn([
'admin' => 'admin', 'admin' => 'admin',
]); ]);
$this->assertEquals($board, $this->service->delete(123)); $boardDeleted = clone $board;
$board->setDeletedAt(1);
$this->boardMapper->expects($this->once())
->method('update')
->willReturn($boardDeleted);
$this->assertEquals($boardDeleted, $this->service->delete(123));
} }
public function testAddAcl() { public function testAddAcl() {

View File

@@ -24,6 +24,7 @@
namespace OCA\Deck\Service; namespace OCA\Deck\Service;
use OCA\Deck\Activity\ActivityManager;
use OCA\Deck\Db\AssignedUsers; use OCA\Deck\Db\AssignedUsers;
use OCA\Deck\Db\AssignedUsersMapper; use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\Card; use OCA\Deck\Db\Card;
@@ -34,6 +35,7 @@ use OCA\Deck\Db\LabelMapper;
use OCA\Deck\NotFoundException; use OCA\Deck\NotFoundException;
use OCA\Deck\Notification\NotificationHelper; use OCA\Deck\Notification\NotificationHelper;
use OCA\Deck\StatusException; use OCA\Deck\StatusException;
use OCP\Activity\IEvent;
use Test\TestCase; use Test\TestCase;
class CardServiceTest extends TestCase { class CardServiceTest extends TestCase {
@@ -55,7 +57,10 @@ class CardServiceTest extends TestCase {
/** @var LabelMapper|\PHPUnit\Framework\MockObject\MockObject */ /** @var LabelMapper|\PHPUnit\Framework\MockObject\MockObject */
private $labelMapper; private $labelMapper;
private $boardMapper; private $boardMapper;
/** @var AttachmentService|\PHPUnit\Framework\MockObject\MockObject */
private $attachmentService; private $attachmentService;
/** @var ActivityManager|\PHPUnit\Framework\MockObject\MockObject */
private $activityManager;
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
@@ -68,7 +73,8 @@ class CardServiceTest extends TestCase {
$this->notificationHelper = $this->createMock(NotificationHelper::class); $this->notificationHelper = $this->createMock(NotificationHelper::class);
$this->assignedUsersMapper = $this->createMock(AssignedUsersMapper::class); $this->assignedUsersMapper = $this->createMock(AssignedUsersMapper::class);
$this->attachmentService = $this->createMock(AttachmentService::class); $this->attachmentService = $this->createMock(AttachmentService::class);
$this->cardService = new CardService( $this->activityManager = $this->createMock(ActivityManager::class);
$this->cardService = new CardService(
$this->cardMapper, $this->cardMapper,
$this->stackMapper, $this->stackMapper,
$this->boardMapper, $this->boardMapper,
@@ -78,10 +84,23 @@ class CardServiceTest extends TestCase {
$this->notificationHelper, $this->notificationHelper,
$this->assignedUsersMapper, $this->assignedUsersMapper,
$this->attachmentService, $this->attachmentService,
$this->activityManager,
'user1' 'user1'
); );
} }
public function mockActivity($type, $object, $subject) {
// ActivityManager::DECK_OBJECT_BOARD, $newAcl, ActivityManager::SUBJECT_BOARD_SHARE
$event = $this->createMock(IEvent::class);
$this->activityManager->expects($this->once())
->method('createEvent')
->with($type, $object, $subject)
->willReturn($event);
$this->activityManager->expects($this->once())
->method('sendToUsers')
->with($event);
}
public function testFind() { public function testFind() {
$card = new Card(); $card = new Card();
$card->setId(1337); $card->setId(1337);

View File

@@ -25,6 +25,7 @@ namespace OCA\Deck\Service;
use OCA\Deck\Activity\ActivityManager;
use OCA\Deck\Db\AssignedUsersMapper; use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\Card; use OCA\Deck\Db\Card;
use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\CardMapper;
@@ -63,6 +64,8 @@ class StackServiceTest extends TestCase {
private $boardService; private $boardService;
/** @var CardService|\PHPUnit\Framework\MockObject\MockObject */ /** @var CardService|\PHPUnit\Framework\MockObject\MockObject */
private $cardService; private $cardService;
/** @var ActivityManager|\PHPUnit\Framework\MockObject\MockObject */
private $activityManager;
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
@@ -75,18 +78,19 @@ class StackServiceTest extends TestCase {
$this->assignedUsersMapper = $this->createMock(AssignedUsersMapper::class); $this->assignedUsersMapper = $this->createMock(AssignedUsersMapper::class);
$this->attachmentService = $this->createMock(AttachmentService::class); $this->attachmentService = $this->createMock(AttachmentService::class);
$this->labelMapper = $this->createMock(LabelMapper::class); $this->labelMapper = $this->createMock(LabelMapper::class);
$this->activityManager = $this->createMock(ActivityManager::class);
$this->stackService = new StackService( $this->stackService = new StackService(
$this->stackMapper, $this->stackMapper,
$this->boardMapper, $this->boardMapper,
$this->cardMapper, $this->cardMapper,
$this->labelMapper, $this->labelMapper,
$this->permissionService, $this->permissionService,
$this->boardService, $this->boardService,
$this->cardService, $this->cardService,
$this->assignedUsersMapper, $this->assignedUsersMapper,
$this->attachmentService $this->attachmentService,
$this->activityManager
); );
} }
@@ -176,14 +180,16 @@ class StackServiceTest extends TestCase {
} }
public function testDelete() { public function testDelete() {
$this->permissionService->expects($this->once())->method('checkPermission'); $this->permissionService->expects($this->once())->method('checkPermission');
$stackToBeDeleted = new Stack(); $stackToBeDeleted = new Stack();
$stackToBeDeleted->setId(1); $stackToBeDeleted->setId(1);
$this->stackMapper->expects($this->once())->method('find')->willReturn($stackToBeDeleted); $this->stackMapper->expects($this->once())->method('find')->willReturn($stackToBeDeleted);
$this->stackMapper->expects($this->once())->method('update'); $this->stackMapper->expects($this->once())->method('update')->willReturn($stackToBeDeleted);
$this->stackService->delete(123); $this->stackService->delete(123);
$this->assertTrue($stackToBeDeleted->getDeletedAt() <= time(), "deletedAt is in the past"); $this->assertTrue($stackToBeDeleted->getDeletedAt() <= time(), "deletedAt is in the past");
} $this->assertTrue($stackToBeDeleted->getDeletedAt() > 0, "deletedAt is set");
}
public function testUpdate() { public function testUpdate() {
$this->permissionService->expects($this->once())->method('checkPermission'); $this->permissionService->expects($this->once())->method('checkPermission');