diff --git a/lib/Service/CardService.php b/lib/Service/CardService.php index 4e2a4a9d2..d841d02bc 100644 --- a/lib/Service/CardService.php +++ b/lib/Service/CardService.php @@ -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); diff --git a/tests/unit/Service/BoardServiceTest.php b/tests/unit/Service/BoardServiceTest.php index a60955123..7ff2ed004 100644 --- a/tests/unit/Service/BoardServiceTest.php +++ b/tests/unit/Service/BoardServiceTest.php @@ -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() { diff --git a/tests/unit/Service/CardServiceTest.php b/tests/unit/Service/CardServiceTest.php index 31fe4b1a6..f7f583e0a 100644 --- a/tests/unit/Service/CardServiceTest.php +++ b/tests/unit/Service/CardServiceTest.php @@ -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); } diff --git a/tests/unit/Service/LabelServiceTest.php b/tests/unit/Service/LabelServiceTest.php index 561b07859..152bccdb2 100644 --- a/tests/unit/Service/LabelServiceTest.php +++ b/tests/unit/Service/LabelServiceTest.php @@ -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 ); } diff --git a/tests/unit/Service/StackServiceTest.php b/tests/unit/Service/StackServiceTest.php index ba6c6e5b6..7ffff8236 100644 --- a/tests/unit/Service/StackServiceTest.php +++ b/tests/unit/Service/StackServiceTest.php @@ -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 ); } diff --git a/tests/unit/controller/BoardControllerTest.php b/tests/unit/controller/BoardControllerTest.php index 66b56ca74..439521206 100644 --- a/tests/unit/controller/BoardControllerTest.php +++ b/tests/unit/controller/BoardControllerTest.php @@ -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() {