Fix unit tests for board archiving

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2017-05-17 19:51:06 +02:00
parent 8c04ea8dc9
commit 90eb9ce28e
6 changed files with 31 additions and 17 deletions

View File

@@ -172,7 +172,7 @@ class CardService {
public function removeLabel($cardId, $labelId) {
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);
if($this->boardService->isArchived($this->cardMapper, $id)) {
if($this->boardService->isArchived($this->cardMapper, $cardId)) {
throw new StatusException('Operation not allowed. This board is archived.');
}
$card = $this->cardMapper->find($cardId);

View File

@@ -134,11 +134,12 @@ class BoardServiceTest extends \Test\TestCase {
->method('update')
->with($board)
->willReturn($board);
$b = $this->service->update(123, 'MyNewNameBoard', 'ffffff');
$b = $this->service->update(123, 'MyNewNameBoard', 'ffffff', false);
$this->assertEquals($b->getTitle(), 'MyNewNameBoard');
$this->assertEquals($b->getOwner(), 'admin');
$this->assertEquals($b->getColor(), 'ffffff');
$this->assertEquals($b->getArchived(), false);
}
public function testDelete() {

View File

@@ -27,9 +27,10 @@ namespace OCA\Deck\Service;
use OCA\Deck\Db\Card;
use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\StackMapper;
use OCA\Deck\ArchivedItemException;
use OCA\Deck\StatusException;
use Test\TestCase;
class CardServiceTest extends \PHPUnit_Framework_TestCase {
class CardServiceTest extends TestCase {
/** @var CardService|\PHPUnit_Framework_MockObject_MockObject */
private $cardService;
@@ -39,7 +40,8 @@ class CardServiceTest extends \PHPUnit_Framework_TestCase {
private $stackMapper;
/** @var PermissionService|\PHPUnit_Framework_MockObject_MockObject */
private $permissionService;
/** @var BoardService|\PHPUnit_Framework_MockObject_MockObject */
private $boardService;
public function setUp() {
$this->cardMapper = $this->getMockBuilder(CardMapper::class)
@@ -48,7 +50,8 @@ class CardServiceTest extends \PHPUnit_Framework_TestCase {
->disableOriginalConstructor()->getMock();
$this->permissionService = $this->getMockBuilder(PermissionService::class)
->disableOriginalConstructor()->getMock();
$this->cardService = new CardService($this->cardMapper, $this->stackMapper, $this->permissionService);
$this->boardService = $this->createMock(BoardService::class);
$this->cardService = new CardService($this->cardMapper, $this->stackMapper, $this->permissionService, $this->boardService);
}
public function testFind() {
@@ -108,7 +111,7 @@ class CardServiceTest extends \PHPUnit_Framework_TestCase {
$card->setArchived(true);
$this->cardMapper->expects($this->once())->method('find')->willReturn($card);
$this->cardMapper->expects($this->never())->method('update');
$this->setExpectedException(ArchivedItemException::class);
$this->setExpectedException(StatusException::class);
$this->cardService->update(123, 'newtitle', 234, 'text', 999, 'foo', 'admin');
}
@@ -128,7 +131,7 @@ class CardServiceTest extends \PHPUnit_Framework_TestCase {
$card->setArchived(true);
$this->cardMapper->expects($this->once())->method('find')->willReturn($card);
$this->cardMapper->expects($this->never())->method('update');
$this->setExpectedException(ArchivedItemException::class);
$this->setExpectedException(StatusException::class);
$this->cardService->rename(123, 'newtitle');
}
@@ -168,7 +171,7 @@ class CardServiceTest extends \PHPUnit_Framework_TestCase {
$card->setArchived(true);
$this->cardMapper->expects($this->once())->method('findAll')->willReturn([$card]);
$this->cardMapper->expects($this->never())->method('update')->willReturnCallback(function($c) { return $c; });
$this->setExpectedException(ArchivedItemException::class);
$this->setExpectedException(StatusException::class);
$actual = $this->cardService->reorder(123, 234, 1);
}
public function testArchive() {
@@ -204,7 +207,7 @@ class CardServiceTest extends \PHPUnit_Framework_TestCase {
$card->setArchived(true);
$this->cardMapper->expects($this->once())->method('find')->willReturn($card);
$this->cardMapper->expects($this->never())->method('assignLabel');
$this->setExpectedException(ArchivedItemException::class);
$this->setExpectedException(StatusException::class);
$this->cardService->assignLabel(123, 999);
}
@@ -221,7 +224,7 @@ class CardServiceTest extends \PHPUnit_Framework_TestCase {
$card->setArchived(true);
$this->cardMapper->expects($this->once())->method('find')->willReturn($card);
$this->cardMapper->expects($this->never())->method('removeLabel');
$this->setExpectedException(ArchivedItemException::class);
$this->setExpectedException(StatusException::class);
$this->cardService->removeLabel(123, 999);
}

View File

@@ -26,8 +26,9 @@ namespace OCA\Deck\Service;
use OCA\Deck\Db\Label;
use OCA\Deck\Db\LabelMapper;
use Test\TestCase;
class LabelServiceTest extends \PHPUnit_Framework_TestCase {
class LabelServiceTest extends TestCase {
/** @var LabelMapper|\PHPUnit_Framework_MockObject_MockObject */
private $labelMapper;
@@ -35,15 +36,19 @@ class LabelServiceTest extends \PHPUnit_Framework_TestCase {
private $permissionService;
/** @var LabelService */
private $labelService;
/** @var BoardService|\PHPUnit_Framework_MockObject_MockObject */
private $boardService;
public function setUp() {
$this->labelMapper = $this->getMockBuilder(LabelMapper::class)
->disableOriginalConstructor()->getMock();
$this->permissionService = $this->getMockBuilder(PermissionService::class)
->disableOriginalConstructor()->getMock();
$this->boardService = $this->createMock(BoardService::class);
$this->labelService = new LabelService(
$this->labelMapper,
$this->permissionService
$this->permissionService,
$this->boardService
);
}

View File

@@ -31,8 +31,9 @@ use OCA\Deck\Db\Label;
use OCA\Deck\Db\LabelMapper;
use OCA\Deck\Db\Stack;
use OCA\Deck\Db\StackMapper;
use Test\TestCase;
class StackServiceTest extends \PHPUnit_Framework_TestCase {
class StackServiceTest extends TestCase {
/** @var StackService */
private $stackService;
@@ -44,6 +45,8 @@ class StackServiceTest extends \PHPUnit_Framework_TestCase {
private $labelMapper;
/** @var \PHPUnit_Framework_MockObject_MockObject|PermissionService */
private $permissionService;
/** @var BoardService|\PHPUnit_Framework_MockObject_MockObject */
private $boardService;
public function setUp() {
$this->stackMapper = $this->getMockBuilder(StackMapper::class)
@@ -54,12 +57,14 @@ class StackServiceTest extends \PHPUnit_Framework_TestCase {
->disableOriginalConstructor()->getMock();
$this->permissionService = $this->getMockBuilder(PermissionService::class)
->disableOriginalConstructor()->getMock();
$this->boardService = $this->createMock(BoardService::class);
$this->stackService = new StackService(
$this->stackMapper,
$this->cardMapper,
$this->labelMapper,
$this->permissionService
$this->permissionService,
$this->boardService
);
}

View File

@@ -107,9 +107,9 @@ class BoardControllerTest extends \PHPUnit_Framework_TestCase {
public function testUpdate() {
$this->boardService->expects($this->once())
->method('update')
->with(1, 2, 3)
->with(1, 2, 3, false)
->willReturn(1);
$this->assertEquals(1, $this->controller->update(1, 2, 3));
$this->assertEquals(1, $this->controller->update(1, 2, 3, false));
}
public function testDelete() {