From e208fd8222f457f3865f14d8feadfd822a4d754f Mon Sep 17 00:00:00 2001 From: Ryan Fletcher Date: Tue, 10 Jul 2018 17:10:27 -0400 Subject: [PATCH 01/15] First Attempt at implementing createDefaultBoard() Signed-off-by: Ryan Fletcher --- lib/Controller/PageController.php | 18 +++++++- lib/Service/DefaultBoardService.php | 65 +++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 lib/Service/DefaultBoardService.php diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 6e06db25d..aa9ad59a1 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -23,17 +23,25 @@ namespace OCA\Deck\Controller; +use OCA\Deck\Service\DefaultBoardService; use OCP\IRequest; use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Controller; class PageController extends Controller { + protected $defaultBoardService; private $userId; - public function __construct($AppName, IRequest $request, $userId) { + public function __construct( + $AppName, + IRequest $request, + $userId, + DefaultBoardService $defaultBoardService) { parent::__construct($AppName, $request); + $this->userId = $userId; + $this->boardService = $boardService; } /** @@ -48,6 +56,14 @@ class PageController extends Controller { 'user' => $this->userId, 'maxUploadSize' => \OCP\Util::uploadLimit(), ]; + + // run the checkFirstRun() method from OCA\Deck\Service\DefaultBoardService here + // if the board is not created, then run createDefaultBoard() from the defaultBoardService here. + if ($this->defaultBoardService->checkFirstRun($this->userId)) { + $this->defaultBoardService->createDefaultBoard(); + } + + return new TemplateResponse('deck', 'main', $params); } diff --git a/lib/Service/DefaultBoardService.php b/lib/Service/DefaultBoardService.php new file mode 100644 index 000000000..55afbbb60 --- /dev/null +++ b/lib/Service/DefaultBoardService.php @@ -0,0 +1,65 @@ + + * + * @author Ryan Fletcher + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Deck\Service; + +use OCA\Deck\Service\BoardService; +use OCA\Deck\Service\StackService; +use OCA\Deck\Service\CardService; + +class DefaultBoardService { + + protected $boardService; + protected $stackService; + protected $cardService; + + public function __construct(BoardService $boardService, StackService $stackService, CardService $cardService) { + $this->boardService = $boardService; + $this->stackService = $stackService; + } + + + public function checkFirstRun($userId) { + // Add a user config value like 'firstrun' to check if the default board + // has already been created for the user + + // TODO: Remove hardcode once I figure out how to do the config value. + return true; + } + + public function createDefaultBoard($title, $userId, $color) { + $defaultBoard = $this->boardService->create($title, $userId, $color); + $defaultStacks = []; + $defaultCards = []; + + $boardId = $defaultBoard->getId(); + + $defaultStacks[] = $this->stackService->create('To do', $boardId, 1); + $defaultStacks[] = $this->stackService->create('Doing', $boardId, 1); + $defaultStacks[] = $this->stackService->create('Done', $boardId, 1); + + $defaultCards[] = $this->cardService->create('Example Task 3', $stacks[0]->getId(), 'text', 0, $userId); + $defaultCards[] = $this->cardService->create('Example Task 2', $stacks[1]->getId(), 'text', 0, $userId); + $defaultCards[] = $this->cardService->create('Example Task 1', $stacks[2]->getId(), 'text', 0, $userId); + } +} \ No newline at end of file From 683354da9d89a5275aa18a32ca3845e793ef1b29 Mon Sep 17 00:00:00 2001 From: Ryan Fletcher Date: Tue, 10 Jul 2018 19:29:55 -0400 Subject: [PATCH 02/15] corrected null errors from first attempt. Signed-off-by: Ryan Fletcher --- lib/Controller/PageController.php | 11 ++++++----- lib/Service/DefaultBoardService.php | 15 ++++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index aa9ad59a1..8670e61ce 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -30,18 +30,19 @@ use OCP\AppFramework\Controller; class PageController extends Controller { - protected $defaultBoardService; + private $defaultBoardService; private $userId; public function __construct( $AppName, IRequest $request, - $userId, - DefaultBoardService $defaultBoardService) { + DefaultBoardService $defaultBoardService, + $userId + ) { parent::__construct($AppName, $request); $this->userId = $userId; - $this->boardService = $boardService; + $this->defaultBoardService = $defaultBoardService; } /** @@ -60,7 +61,7 @@ class PageController extends Controller { // run the checkFirstRun() method from OCA\Deck\Service\DefaultBoardService here // if the board is not created, then run createDefaultBoard() from the defaultBoardService here. if ($this->defaultBoardService->checkFirstRun($this->userId)) { - $this->defaultBoardService->createDefaultBoard(); + $this->defaultBoardService->createDefaultBoard('Personal', $this->userId, '000000'); } diff --git a/lib/Service/DefaultBoardService.php b/lib/Service/DefaultBoardService.php index 55afbbb60..a93a28d7e 100644 --- a/lib/Service/DefaultBoardService.php +++ b/lib/Service/DefaultBoardService.php @@ -33,9 +33,14 @@ class DefaultBoardService { protected $stackService; protected $cardService; - public function __construct(BoardService $boardService, StackService $stackService, CardService $cardService) { + public function __construct( + BoardService $boardService, + StackService $stackService, + CardService $cardService) { + $this->boardService = $boardService; $this->stackService = $stackService; + $this->cardService = $cardService; } @@ -44,7 +49,7 @@ class DefaultBoardService { // has already been created for the user // TODO: Remove hardcode once I figure out how to do the config value. - return true; + return false; } public function createDefaultBoard($title, $userId, $color) { @@ -58,8 +63,8 @@ class DefaultBoardService { $defaultStacks[] = $this->stackService->create('Doing', $boardId, 1); $defaultStacks[] = $this->stackService->create('Done', $boardId, 1); - $defaultCards[] = $this->cardService->create('Example Task 3', $stacks[0]->getId(), 'text', 0, $userId); - $defaultCards[] = $this->cardService->create('Example Task 2', $stacks[1]->getId(), 'text', 0, $userId); - $defaultCards[] = $this->cardService->create('Example Task 1', $stacks[2]->getId(), 'text', 0, $userId); + $defaultCards[] = $this->cardService->create('Example Task 3', $defaultStacks[0]->getId(), 'text', 0, $userId); + $defaultCards[] = $this->cardService->create('Example Task 2', $defaultStacks[1]->getId(), 'text', 0, $userId); + $defaultCards[] = $this->cardService->create('Example Task 1', $defaultStacks[2]->getId(), 'text', 0, $userId); } } \ No newline at end of file From a36dfcc14448422da75a5fc8048f74593e4893df Mon Sep 17 00:00:00 2001 From: Ryan Fletcher Date: Tue, 10 Jul 2018 21:16:24 -0400 Subject: [PATCH 03/15] first attempt at writing the checkFirstRun() in DefaultBoardService.php Signed-off-by: Ryan Fletcher --- lib/Controller/PageController.php | 7 ++----- lib/Service/DefaultBoardService.php | 27 +++++++++++++++++---------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 8670e61ce..7a51bffd5 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -57,14 +57,11 @@ class PageController extends Controller { 'user' => $this->userId, 'maxUploadSize' => \OCP\Util::uploadLimit(), ]; - - // run the checkFirstRun() method from OCA\Deck\Service\DefaultBoardService here - // if the board is not created, then run createDefaultBoard() from the defaultBoardService here. - if ($this->defaultBoardService->checkFirstRun($this->userId)) { + + if ($this->defaultBoardService->checkFirstRun($this->userId, $AppName)) { $this->defaultBoardService->createDefaultBoard('Personal', $this->userId, '000000'); } - return new TemplateResponse('deck', 'main', $params); } diff --git a/lib/Service/DefaultBoardService.php b/lib/Service/DefaultBoardService.php index a93a28d7e..33463e958 100644 --- a/lib/Service/DefaultBoardService.php +++ b/lib/Service/DefaultBoardService.php @@ -26,29 +26,36 @@ namespace OCA\Deck\Service; use OCA\Deck\Service\BoardService; use OCA\Deck\Service\StackService; use OCA\Deck\Service\CardService; +use OCP\IConfig; class DefaultBoardService { - protected $boardService; - protected $stackService; - protected $cardService; + private $boardService; + private $stackService; + private $cardService; + private $config; public function __construct( BoardService $boardService, StackService $stackService, - CardService $cardService) { + CardService $cardService, + IConfig $config + ) { $this->boardService = $boardService; $this->stackService = $stackService; $this->cardService = $cardService; + $this->config = $config; } - - public function checkFirstRun($userId) { - // Add a user config value like 'firstrun' to check if the default board - // has already been created for the user + public function checkFirstRun($userId, $appName) { + $firstRun = $this->config->getUserValue($userId,$appName,'firstRun','yes'); + + if ($firstRun == 'yes') { + $this->config->setUserValue($userId,$appName,'firstRun','no'); + return true; + } - // TODO: Remove hardcode once I figure out how to do the config value. return false; } @@ -66,5 +73,5 @@ class DefaultBoardService { $defaultCards[] = $this->cardService->create('Example Task 3', $defaultStacks[0]->getId(), 'text', 0, $userId); $defaultCards[] = $this->cardService->create('Example Task 2', $defaultStacks[1]->getId(), 'text', 0, $userId); $defaultCards[] = $this->cardService->create('Example Task 1', $defaultStacks[2]->getId(), 'text', 0, $userId); - } + } } \ No newline at end of file From 8a8cffc54227a38dabaf2ea3522f97f9d6a89fef Mon Sep 17 00:00:00 2001 From: Ryan Fletcher Date: Wed, 11 Jul 2018 08:02:54 -0400 Subject: [PATCH 04/15] Completed checkFirstRun() in DefaultBoardService.php Signed-off-by: Ryan Fletcher --- lib/Controller/PageController.php | 2 +- lib/Service/DefaultBoardService.php | 65 ++++++++++++++++------------- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 7a51bffd5..0f5234bd4 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -58,7 +58,7 @@ class PageController extends Controller { 'maxUploadSize' => \OCP\Util::uploadLimit(), ]; - if ($this->defaultBoardService->checkFirstRun($this->userId, $AppName)) { + if ($this->defaultBoardService->checkFirstRun($this->userId, $this->appName)) { $this->defaultBoardService->createDefaultBoard('Personal', $this->userId, '000000'); } diff --git a/lib/Service/DefaultBoardService.php b/lib/Service/DefaultBoardService.php index 33463e958..59192b444 100644 --- a/lib/Service/DefaultBoardService.php +++ b/lib/Service/DefaultBoardService.php @@ -1,6 +1,6 @@ + * @copyright Copyright (c) 2018 Ryan Fletcher * * @author Ryan Fletcher * @@ -23,6 +23,7 @@ namespace OCA\Deck\Service; +use OCA\Deck\Db\BoardMapper; use OCA\Deck\Service\BoardService; use OCA\Deck\Service\StackService; use OCA\Deck\Service\CardService; @@ -30,48 +31,52 @@ use OCP\IConfig; class DefaultBoardService { - private $boardService; - private $stackService; - private $cardService; - private $config; + private $boardMapper; + private $boardService; + private $stackService; + private $cardService; + private $config; public function __construct( - BoardService $boardService, - StackService $stackService, - CardService $cardService, - IConfig $config - ) { + BoardMapper $boardMapper, + BoardService $boardService, + StackService $stackService, + CardService $cardService, + IConfig $config + ) { - $this->boardService = $boardService; - $this->stackService = $stackService; - $this->cardService = $cardService; - $this->config = $config; + $this->boardService = $boardService; + $this->stackService = $stackService; + $this->cardService = $cardService; + $this->config = $config; + $this->boardMapper = $boardMapper; } public function checkFirstRun($userId, $appName) { - $firstRun = $this->config->getUserValue($userId,$appName,'firstRun','yes'); + $firstRun = $this->config->getUserValue($userId,$appName,'firstRun','yes'); + $userBoards = $this->boardMapper->findAllByUser($userId); + + if ($firstRun === 'yes' && count($userBoards) === 0) { + $this->config->setUserValue($userId,$appName,'firstRun','no'); + return true; + } - if ($firstRun == 'yes') { - $this->config->setUserValue($userId,$appName,'firstRun','no'); - return true; - } - - return false; + return false; } public function createDefaultBoard($title, $userId, $color) { $defaultBoard = $this->boardService->create($title, $userId, $color); $defaultStacks = []; $defaultCards = []; + + $boardId = $defaultBoard->getId(); + + $defaultStacks[] = $this->stackService->create('To do', $boardId, 1); + $defaultStacks[] = $this->stackService->create('Doing', $boardId, 1); + $defaultStacks[] = $this->stackService->create('Done', $boardId, 1); - $boardId = $defaultBoard->getId(); - - $defaultStacks[] = $this->stackService->create('To do', $boardId, 1); - $defaultStacks[] = $this->stackService->create('Doing', $boardId, 1); - $defaultStacks[] = $this->stackService->create('Done', $boardId, 1); - - $defaultCards[] = $this->cardService->create('Example Task 3', $defaultStacks[0]->getId(), 'text', 0, $userId); - $defaultCards[] = $this->cardService->create('Example Task 2', $defaultStacks[1]->getId(), 'text', 0, $userId); - $defaultCards[] = $this->cardService->create('Example Task 1', $defaultStacks[2]->getId(), 'text', 0, $userId); + $defaultCards[] = $this->cardService->create('Example Task 3', $defaultStacks[0]->getId(), 'text', 0, $userId); + $defaultCards[] = $this->cardService->create('Example Task 2', $defaultStacks[1]->getId(), 'text', 0, $userId); + $defaultCards[] = $this->cardService->create('Example Task 1', $defaultStacks[2]->getId(), 'text', 0, $userId); } } \ No newline at end of file From 61fb68f4cff0da388b82c2bd9a623f0690f8a591 Mon Sep 17 00:00:00 2001 From: Ryan Fletcher Date: Wed, 11 Jul 2018 10:20:42 -0400 Subject: [PATCH 05/15] Added a unit test against DefaultBoardService->TestCreateDefaultBoard() Signed-off-by: Ryan Fletcher --- lib/Service/DefaultBoardService.php | 6 +- .../unit/Service/DefaultBoardServiceTest.php | 150 ++++++++++++++++++ 2 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 tests/unit/Service/DefaultBoardServiceTest.php diff --git a/lib/Service/DefaultBoardService.php b/lib/Service/DefaultBoardService.php index 59192b444..30edf1372 100644 --- a/lib/Service/DefaultBoardService.php +++ b/lib/Service/DefaultBoardService.php @@ -39,8 +39,8 @@ class DefaultBoardService { public function __construct( BoardMapper $boardMapper, - BoardService $boardService, - StackService $stackService, + BoardService $boardService, + StackService $stackService, CardService $cardService, IConfig $config ) { @@ -78,5 +78,7 @@ class DefaultBoardService { $defaultCards[] = $this->cardService->create('Example Task 3', $defaultStacks[0]->getId(), 'text', 0, $userId); $defaultCards[] = $this->cardService->create('Example Task 2', $defaultStacks[1]->getId(), 'text', 0, $userId); $defaultCards[] = $this->cardService->create('Example Task 1', $defaultStacks[2]->getId(), 'text', 0, $userId); + + return $defaultBoard; } } \ No newline at end of file diff --git a/tests/unit/Service/DefaultBoardServiceTest.php b/tests/unit/Service/DefaultBoardServiceTest.php new file mode 100644 index 000000000..21f01d9e3 --- /dev/null +++ b/tests/unit/Service/DefaultBoardServiceTest.php @@ -0,0 +1,150 @@ + + * + * @author Ryan Fletcher + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Deck\Service; + +use OCA\Deck\Db\Card; +use OCA\Deck\Db\Board; +use OCA\Deck\Db\Stack; +use OCA\Deck\Db\BoardMapper; +use OCA\Deck\Service\DefaultBoardService; +use OCA\Deck\Service\BoardService; +use OCA\Deck\Service\StackService; +use OCA\Deck\Service\CardService; +use OCP\IConfig; + +class DefaultBoardServiceTest extends TestCase { + + /** @var DefaultBoardService */ + private $service; + + /** @var BoardService */ + private $boardService; + + /** @var StackService */ + private $stackService; + + /** @var CardService */ + private $cardService; + + /** @var BoardMapper */ + private $boardMapper; + + /** @var IConfig */ + private $config; + + private $userId = 'admin'; + + public function setUp() { + parent::setUp(); + $this->boardService = $this->createMock(BoardService::class); + $this->stackService = $this->createMock(StackService::class); + $this->cardService = $this->createMock(CardService::class); + $this->config = $this->createMock(IConfig::class); + + $this->service = new DefaultBoardService( + $this->boardService, + $this->stackService, + $this->cardService, + $this->config + ); + + $user = $this->createMock(IUser::class); + $user->method('getUID')->willReturn('admin'); + } + + public function testCreateDefaultBoard() { + $title = 'Personal'; + $color = '000000'; + $boardId = 123; + + $board = new Board(); + $board->setBoardId($boardId); + $board->setTitle($title); + $board->setOwner($admin); + $board->setColor($color); + $this->boardMapper->expects($this->once()) + ->method('insert') + ->willReturn($board); + + $stackToDoId = '123'; + $stackToDo = $this->assembleTestStack('To do', $stackToDoId, $boardId); + $this->stackService->expects($this->once()) + ->method('create') + ->willReturn($stackToDo); + + $stackDoingId = '124'; + $stackDone = $this.assembleTestStack('Done', $stackDoingId, $boardId); + $this->stackService->expects($this->once()) + ->method('create') + ->willReturn($stackDoing); + + $stackDoneId = '125'; + $stackDone = $this.assembleTestStack('Done', $stackDoneId, $boardId); + $this->stackService->expects($this->once()) + ->method('create') + ->willReturn($stackDone); + + $cardExampleTask3 = $this.assembleTestCard('Example Task 3', $stackToDoId, $this->userId); + $this->cardService->expects($this->once()) + ->method('create') + ->willReturn($cardExampleTask3); + + $cardExampleTask2 = $this.assembleTestCard('Example Task 2', $stackDoingId, $this->userId); + $this->cardService->expects($this->once()) + ->method('create') + ->willReturn($cardExampleTask2); + + $cardExampleTask1 = $this.assembleTestCard('Example Task 1', $stackDoneId, $this->userId); + $this->cardService->expects($this->once()) + ->method('create') + ->willReturn($cardExampleTask1); + + $result = $this->service->createDefaultBoard($title, $this->userId, $color); + + $this->assertEquals($result->getTitle(), $title); + $this->assertEquals($result->getOwner(), $this->userId); + $this->assertEquals($result->getColor(), $color); + } + + private function assembleTestStack($title, $id, $boardId) { + $stack = new Stack(); + $stack->setId($id); + $stack->setTitle($title); + $stack->setBoardId($boardId); + $stack->setOrder(1); + + return $stack; + } + + private function assembleTestCard($title, $stackId, $userId) { + $card = new Card(); + $card->setTitle($title); + $card->setStackId($stackId); + $card->setType('text'); + $card->setOrder(0); + $card->setUserId($userId); + + return $card; + } +} \ No newline at end of file From e07fc0a2c76c374d68b237a3e08dcaa1b33728ce Mon Sep 17 00:00:00 2001 From: Ryan Fletcher Date: Wed, 11 Jul 2018 10:49:46 -0400 Subject: [PATCH 06/15] Corrected missing import and missing parameter in defaultBoardServiceTest Signed-off-by: Ryan Fletcher --- tests/unit/Service/DefaultBoardServiceTest.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/unit/Service/DefaultBoardServiceTest.php b/tests/unit/Service/DefaultBoardServiceTest.php index 21f01d9e3..8152ce24d 100644 --- a/tests/unit/Service/DefaultBoardServiceTest.php +++ b/tests/unit/Service/DefaultBoardServiceTest.php @@ -32,6 +32,7 @@ use OCA\Deck\Service\BoardService; use OCA\Deck\Service\StackService; use OCA\Deck\Service\CardService; use OCP\IConfig; +use \Test\TestCase; class DefaultBoardServiceTest extends TestCase { @@ -56,13 +57,15 @@ class DefaultBoardServiceTest extends TestCase { private $userId = 'admin'; public function setUp() { - parent::setUp(); + parent::setUp(); + $this->boardMapper = $this->createMock(BoardMapper::class); $this->boardService = $this->createMock(BoardService::class); $this->stackService = $this->createMock(StackService::class); $this->cardService = $this->createMock(CardService::class); $this->config = $this->createMock(IConfig::class); - $this->service = new DefaultBoardService( + $this->service = new DefaultBoardService( + $this->boardMapper, $this->boardService, $this->stackService, $this->cardService, From 712ab9e0bcd6c4b3335eddd331573853aff2b5aa Mon Sep 17 00:00:00 2001 From: Ryan Fletcher Date: Wed, 11 Jul 2018 11:49:20 -0400 Subject: [PATCH 07/15] Corrected testCreateDefaultBoard() Signed-off-by: Ryan Fletcher --- .../unit/Service/DefaultBoardServiceTest.php | 61 ++++++++----------- 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/tests/unit/Service/DefaultBoardServiceTest.php b/tests/unit/Service/DefaultBoardServiceTest.php index 8152ce24d..9bbe6db80 100644 --- a/tests/unit/Service/DefaultBoardServiceTest.php +++ b/tests/unit/Service/DefaultBoardServiceTest.php @@ -70,58 +70,51 @@ class DefaultBoardServiceTest extends TestCase { $this->stackService, $this->cardService, $this->config - ); - - $user = $this->createMock(IUser::class); - $user->method('getUID')->willReturn('admin'); + ); } public function testCreateDefaultBoard() { $title = 'Personal'; $color = '000000'; - $boardId = 123; + $boardId = 5; $board = new Board(); - $board->setBoardId($boardId); + $board->setId($boardId); $board->setTitle($title); - $board->setOwner($admin); + $board->setOwner($this->userId); $board->setColor($color); - $this->boardMapper->expects($this->once()) - ->method('insert') + $this->boardService->expects($this->once()) + ->method('create') ->willReturn($board); $stackToDoId = '123'; - $stackToDo = $this->assembleTestStack('To do', $stackToDoId, $boardId); - $this->stackService->expects($this->once()) - ->method('create') - ->willReturn($stackToDo); + $stackToDo = $this->assembleTestStack('To do', $stackToDoId, $boardId); $stackDoingId = '124'; - $stackDone = $this.assembleTestStack('Done', $stackDoingId, $boardId); - $this->stackService->expects($this->once()) - ->method('create') - ->willReturn($stackDoing); + $stackDoing = $this->assembleTestStack('Doing', $stackDoingId, $boardId); $stackDoneId = '125'; - $stackDone = $this.assembleTestStack('Done', $stackDoneId, $boardId); - $this->stackService->expects($this->once()) + $stackDone = $this->assembleTestStack('Done', $stackDoneId, $boardId); + $this->stackService->expects($this->exactly(3)) ->method('create') - ->willReturn($stackDone); + ->withConsecutive( + ['To do', $boardId, 1], + ['Doing', $boardId, 1], + ['Done', $boardId, 1] + ) + ->willReturnOnConsecutiveCalls($stackToDo, $stackDoing, $stackDone); - $cardExampleTask3 = $this.assembleTestCard('Example Task 3', $stackToDoId, $this->userId); - $this->cardService->expects($this->once()) + $cardExampleTask3 = $this->assembleTestCard('Example Task 3', $stackToDoId, $this->userId); + $cardExampleTask2 = $this->assembleTestCard('Example Task 2', $stackDoingId, $this->userId); + $cardExampleTask1 = $this->assembleTestCard('Example Task 1', $stackDoneId, $this->userId); + $this->cardService->expects($this->exactly(3)) ->method('create') - ->willReturn($cardExampleTask3); - - $cardExampleTask2 = $this.assembleTestCard('Example Task 2', $stackDoingId, $this->userId); - $this->cardService->expects($this->once()) - ->method('create') - ->willReturn($cardExampleTask2); - - $cardExampleTask1 = $this.assembleTestCard('Example Task 1', $stackDoneId, $this->userId); - $this->cardService->expects($this->once()) - ->method('create') - ->willReturn($cardExampleTask1); + ->withConsecutive( + ['Example Task 3', $stackToDoId, 'text', 0, $this->userId], + ['Example Task 2', $stackDoingId, 'text', 0, $this->userId], + ['Example Task 1', $stackDoneId, 'text', 0, $this->userId] + ) + ->willReturnonConsecutiveCalls($cardExampleTask3, $cardExampleTask2, $cardExampleTask1); $result = $this->service->createDefaultBoard($title, $this->userId, $color); @@ -146,7 +139,7 @@ class DefaultBoardServiceTest extends TestCase { $card->setStackId($stackId); $card->setType('text'); $card->setOrder(0); - $card->setUserId($userId); + $card->setOwner($userId); return $card; } From 08f9874745c1093260e5acd2241c01397cc19c2c Mon Sep 17 00:00:00 2001 From: Ryan Fletcher Date: Wed, 11 Jul 2018 11:50:11 -0400 Subject: [PATCH 08/15] Updated constructor in PageControllerTest Signed-off-by: Ryan Fletcher --- tests/unit/controller/PageControllerTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/unit/controller/PageControllerTest.php b/tests/unit/controller/PageControllerTest.php index ff0d444e3..2e7bd778f 100644 --- a/tests/unit/controller/PageControllerTest.php +++ b/tests/unit/controller/PageControllerTest.php @@ -24,6 +24,7 @@ namespace OCA\Deck\Controller; use PHPUnit_Framework_TestCase; +use OCA\Deck\Service\DefaultBoardService; class PageControllerTest extends \Test\TestCase { @@ -31,6 +32,7 @@ class PageControllerTest extends \Test\TestCase { private $request; private $l10n; private $userId = 'john'; + private $defaultBoardService; public function setUp() { $this->l10n = $this->request = $this->getMockBuilder( @@ -42,8 +44,10 @@ class PageControllerTest extends \Test\TestCase { ->disableOriginalConstructor() ->getMock(); + $this->defaultBoardService = $this->createMock(DefaultBoardService::class); + $this->controller = new PageController( - 'deck', $this->request, $this->l10n, $this->userId + 'deck', $this->request, $this->defaultBoardService, $this->l10n, $this->userId ); } From 2002841c6138e4d5f89e71522f34030740c3f24c Mon Sep 17 00:00:00 2001 From: Ryan Fletcher Date: Wed, 11 Jul 2018 12:59:40 -0400 Subject: [PATCH 09/15] Wrote unit tests for checkFirstRun method in the default board service Signed-off-by: Ryan Fletcher --- .../unit/Service/DefaultBoardServiceTest.php | 44 ++++++++++++++++++- tests/unit/controller/PageControllerTest.php | 3 +- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/tests/unit/Service/DefaultBoardServiceTest.php b/tests/unit/Service/DefaultBoardServiceTest.php index 9bbe6db80..ac00ea631 100644 --- a/tests/unit/Service/DefaultBoardServiceTest.php +++ b/tests/unit/Service/DefaultBoardServiceTest.php @@ -73,6 +73,46 @@ class DefaultBoardServiceTest extends TestCase { ); } + public function testCheckFirstRunCaseTrue() { + $appName = "Deck"; + $userBoards = []; + + $this->config->expects($this->once()) + ->method('getUserValue') + ->willReturn('yes'); + + $this->boardMapper->expects($this->once()) + ->method('findAllByUser') + ->willReturn($userBoards); + + $this->config->expects($this->once()) + ->method('setUserValue'); + + $result = $this->service->checkFirstRun($this->userId, $appName); + $this->assertEquals($result, true); + } + + public function testCheckFirstRunCaseFalse() { + $appName = "deck"; + $board = new Board(); + $board->setTitle('Personal'); + $board->setOwner($this->userId); + $board->setColor('000000'); + + $userBoards = [$board]; + + $this->config->expects($this->once()) + ->method('getUserValue') + ->willReturn('no'); + + $this->boardMapper->expects($this->once()) + ->method('findAllByUser') + ->willReturn($userBoards); + + $result = $this->service->checkFirstRun($this->userId, $appName); + $this->assertEquals($result, false); + } + public function testCreateDefaultBoard() { $title = 'Personal'; $color = '000000'; @@ -84,8 +124,8 @@ class DefaultBoardServiceTest extends TestCase { $board->setOwner($this->userId); $board->setColor($color); $this->boardService->expects($this->once()) - ->method('create') - ->willReturn($board); + ->method('create') + ->willReturn($board); $stackToDoId = '123'; $stackToDo = $this->assembleTestStack('To do', $stackToDoId, $boardId); diff --git a/tests/unit/controller/PageControllerTest.php b/tests/unit/controller/PageControllerTest.php index 2e7bd778f..f00272233 100644 --- a/tests/unit/controller/PageControllerTest.php +++ b/tests/unit/controller/PageControllerTest.php @@ -51,7 +51,8 @@ class PageControllerTest extends \Test\TestCase { ); } - + // TODO-ryan: update this test to ensure that checkFirstRun is bieng called, if it is then + // test that the createDefaultBoard is also being called. public function testIndex() { $response = $this->controller->index(); $this->assertEquals('main', $response->getTemplateName()); From be8a3479acc9bad77345c6324aca3ba667006a26 Mon Sep 17 00:00:00 2001 From: Ryan Fletcher Date: Wed, 11 Jul 2018 13:33:04 -0400 Subject: [PATCH 10/15] Updated PageControllerTest.php to reflect new changes Signed-off-by: Ryan Fletcher --- tests/unit/controller/PageControllerTest.php | 36 +++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/tests/unit/controller/PageControllerTest.php b/tests/unit/controller/PageControllerTest.php index f00272233..ce0d40b2a 100644 --- a/tests/unit/controller/PageControllerTest.php +++ b/tests/unit/controller/PageControllerTest.php @@ -3,6 +3,7 @@ * @copyright Copyright (c) 2016 Julius Härtl * * @author Julius Härtl + * @author Ryan Fletcher * * @license GNU AGPL version 3 or any later version * @@ -25,6 +26,8 @@ namespace OCA\Deck\Controller; use PHPUnit_Framework_TestCase; use OCA\Deck\Service\DefaultBoardService; +use OCA\Deck\Db\Board; +use OCP\IConfig; class PageControllerTest extends \Test\TestCase { @@ -33,6 +36,7 @@ class PageControllerTest extends \Test\TestCase { private $l10n; private $userId = 'john'; private $defaultBoardService; + private $config; public function setUp() { $this->l10n = $this->request = $this->getMockBuilder( @@ -45,18 +49,42 @@ class PageControllerTest extends \Test\TestCase { ->getMock(); $this->defaultBoardService = $this->createMock(DefaultBoardService::class); + $this->config = $this->createMock(IConfig::class); $this->controller = new PageController( 'deck', $this->request, $this->defaultBoardService, $this->l10n, $this->userId ); } + + public function testIndexOnFirstRun() { + + $board = new Board(); + $board->setTitle("Personal"); + $board->setOwner($this->userId); + $board->setColor('000000'); + + $this->defaultBoardService->expects($this->once()) + ->method('checkFirstRun') + ->willReturn(true); + + $this->defaultBoardService->expects($this->once()) + ->method('createDefaultBoard') + ->willReturn($board); + + $response = $this->controller->index(); + $this->assertEquals('main', $response->getTemplateName()); + } + + public function testIndexOnSecondRun() { + + $this->config->setUserValue($this->userId,'deck','firstRun','no'); + + $this->defaultBoardService->expects($this->once()) + ->method('checkFirstRun') + ->willReturn(false); - // TODO-ryan: update this test to ensure that checkFirstRun is bieng called, if it is then - // test that the createDefaultBoard is also being called. - public function testIndex() { $response = $this->controller->index(); $this->assertEquals('main', $response->getTemplateName()); } - } \ No newline at end of file From ba378ea00b36f5a13ff20f0e869a65de153cf791 Mon Sep 17 00:00:00 2001 From: Ryan Fletcher Date: Wed, 11 Jul 2018 15:00:08 -0400 Subject: [PATCH 11/15] First attempt at using l10n Signed-off-by: Ryan Fletcher --- l10n/en_GB.js | 4 +++- l10n/en_GB.json | 4 +++- lib/Controller/PageController.php | 10 ++++++--- lib/Service/DefaultBoardService.php | 22 +++++++++++-------- .../unit/Service/DefaultBoardServiceTest.php | 9 ++++++++ 5 files changed, 35 insertions(+), 14 deletions(-) diff --git a/l10n/en_GB.js b/l10n/en_GB.js index 8266fb71c..d1d628190 100644 --- a/l10n/en_GB.js +++ b/l10n/en_GB.js @@ -74,6 +74,8 @@ OC.L10N.register( "Shared boards" : "Shared boards", "View more" : "View more", "Move board to archive" : "Move board to archive", - "Create a new board" : "Create a new board" + "Create a new board" : "Create a new board", + "Personal": "Personal", + "To do": "To do" }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/en_GB.json b/l10n/en_GB.json index c394f0559..1dde03650 100644 --- a/l10n/en_GB.json +++ b/l10n/en_GB.json @@ -72,6 +72,8 @@ "Shared boards" : "Shared boards", "View more" : "View more", "Move board to archive" : "Move board to archive", - "Create a new board" : "Create a new board" + "Create a new board" : "Create a new board", + "Personal": "Personal", + "To do": "To do" },"pluralForm" :"nplurals=2; plural=(n != 1);" } \ No newline at end of file diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 0f5234bd4..42603a232 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -27,22 +27,26 @@ use OCA\Deck\Service\DefaultBoardService; use OCP\IRequest; use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Controller; +use OCP\IL10N; class PageController extends Controller { private $defaultBoardService; private $userId; + private $l10n; public function __construct( $AppName, - IRequest $request, + IRequest $request, DefaultBoardService $defaultBoardService, + IL10N $l10n, $userId ) { parent::__construct($AppName, $request); $this->userId = $userId; $this->defaultBoardService = $defaultBoardService; + $this->l10n = $l10n; } /** @@ -57,9 +61,9 @@ class PageController extends Controller { 'user' => $this->userId, 'maxUploadSize' => \OCP\Util::uploadLimit(), ]; - + if ($this->defaultBoardService->checkFirstRun($this->userId, $this->appName)) { - $this->defaultBoardService->createDefaultBoard('Personal', $this->userId, '000000'); + $this->defaultBoardService->createDefaultBoard($this->l10n->t('Personal'), $this->userId, '000000'); } return new TemplateResponse('deck', 'main', $params); diff --git a/lib/Service/DefaultBoardService.php b/lib/Service/DefaultBoardService.php index 30edf1372..8f3a7cdf9 100644 --- a/lib/Service/DefaultBoardService.php +++ b/lib/Service/DefaultBoardService.php @@ -28,6 +28,7 @@ use OCA\Deck\Service\BoardService; use OCA\Deck\Service\StackService; use OCA\Deck\Service\CardService; use OCP\IConfig; +use OCP\IL10N; class DefaultBoardService { @@ -36,8 +37,10 @@ class DefaultBoardService { private $stackService; private $cardService; private $config; + private $l10n; public function __construct( + IL10N $l10n, BoardMapper $boardMapper, BoardService $boardService, StackService $stackService, @@ -50,6 +53,7 @@ class DefaultBoardService { $this->cardService = $cardService; $this->config = $config; $this->boardMapper = $boardMapper; + $this->l10n = $l10n; } public function checkFirstRun($userId, $appName) { @@ -69,16 +73,16 @@ class DefaultBoardService { $defaultStacks = []; $defaultCards = []; - $boardId = $defaultBoard->getId(); - - $defaultStacks[] = $this->stackService->create('To do', $boardId, 1); - $defaultStacks[] = $this->stackService->create('Doing', $boardId, 1); - $defaultStacks[] = $this->stackService->create('Done', $boardId, 1); + $boardId = $defaultBoard->getId(); + + $defaultStacks[] = $this->stackService->create($this->l10n->t('To do'), $boardId, 1); + $defaultStacks[] = $this->stackService->create($this->l10n->t('Doing'), $boardId, 1); + $defaultStacks[] = $this->stackService->create($this->l10n->t('Done'), $boardId, 1); - $defaultCards[] = $this->cardService->create('Example Task 3', $defaultStacks[0]->getId(), 'text', 0, $userId); - $defaultCards[] = $this->cardService->create('Example Task 2', $defaultStacks[1]->getId(), 'text', 0, $userId); - $defaultCards[] = $this->cardService->create('Example Task 1', $defaultStacks[2]->getId(), 'text', 0, $userId); + $defaultCards[] = $this->cardService->create($this->l10n->t('Example Task 3'), $defaultStacks[0]->getId(), 'text', 0, $userId); + $defaultCards[] = $this->cardService->create($this->l10n->t('Example Task 2'), $defaultStacks[1]->getId(), 'text', 0, $userId); + $defaultCards[] = $this->cardService->create($this->l10n->t('Example Task 1'), $defaultStacks[2]->getId(), 'text', 0, $userId); return $defaultBoard; - } + } } \ No newline at end of file diff --git a/tests/unit/Service/DefaultBoardServiceTest.php b/tests/unit/Service/DefaultBoardServiceTest.php index ac00ea631..dcac93ca8 100644 --- a/tests/unit/Service/DefaultBoardServiceTest.php +++ b/tests/unit/Service/DefaultBoardServiceTest.php @@ -32,6 +32,7 @@ use OCA\Deck\Service\BoardService; use OCA\Deck\Service\StackService; use OCA\Deck\Service\CardService; use OCP\IConfig; +use OCP\IL10N; use \Test\TestCase; class DefaultBoardServiceTest extends TestCase { @@ -53,6 +54,8 @@ class DefaultBoardServiceTest extends TestCase { /** @var IConfig */ private $config; + + private $l10n; private $userId = 'admin'; @@ -63,8 +66,14 @@ class DefaultBoardServiceTest extends TestCase { $this->stackService = $this->createMock(StackService::class); $this->cardService = $this->createMock(CardService::class); $this->config = $this->createMock(IConfig::class); + + $this->l10n = $this->request = $this->getMockBuilder( + '\OCP\IL10n') + ->disableOriginalConstructor() + ->getMock(); $this->service = new DefaultBoardService( + $this->l10n, $this->boardMapper, $this->boardService, $this->stackService, From af92da9a7cf5c71d37a7f991175a7dd656d30f35 Mon Sep 17 00:00:00 2001 From: Ryan Fletcher Date: Wed, 11 Jul 2018 16:18:00 -0400 Subject: [PATCH 12/15] Removing translations I attempted to put in before knowing the process. Signed-off-by: Ryan Fletcher --- l10n/en_GB.js | 4 +--- l10n/en_GB.json | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/l10n/en_GB.js b/l10n/en_GB.js index d1d628190..a9c375117 100644 --- a/l10n/en_GB.js +++ b/l10n/en_GB.js @@ -74,8 +74,6 @@ OC.L10N.register( "Shared boards" : "Shared boards", "View more" : "View more", "Move board to archive" : "Move board to archive", - "Create a new board" : "Create a new board", - "Personal": "Personal", - "To do": "To do" + "Create a new board" : "Create a new board" }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/en_GB.json b/l10n/en_GB.json index 1dde03650..4366eef90 100644 --- a/l10n/en_GB.json +++ b/l10n/en_GB.json @@ -72,8 +72,6 @@ "Shared boards" : "Shared boards", "View more" : "View more", "Move board to archive" : "Move board to archive", - "Create a new board" : "Create a new board", - "Personal": "Personal", - "To do": "To do" + "Create a new board" : "Create a new board" },"pluralForm" :"nplurals=2; plural=(n != 1);" } \ No newline at end of file From 8d4dbd4d829f0736fa961d9bb702b3b2c1b072b1 Mon Sep 17 00:00:00 2001 From: Ryan Fletcher Date: Thu, 12 Jul 2018 11:17:11 -0400 Subject: [PATCH 13/15] Fixed up code styles as per review by juliushaertl Signed-off-by: Ryan Fletcher --- lib/Service/DefaultBoardService.php | 4 ++-- tests/unit/Service/DefaultBoardServiceTest.php | 10 +++------- tests/unit/controller/PageControllerTest.php | 4 ++-- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/Service/DefaultBoardService.php b/lib/Service/DefaultBoardService.php index 8f3a7cdf9..f79b8d24e 100644 --- a/lib/Service/DefaultBoardService.php +++ b/lib/Service/DefaultBoardService.php @@ -57,11 +57,11 @@ class DefaultBoardService { } public function checkFirstRun($userId, $appName) { - $firstRun = $this->config->getUserValue($userId,$appName,'firstRun','yes'); + $firstRun = $this->config->getUserValue($userId, $appName, 'firstRun', 'yes'); $userBoards = $this->boardMapper->findAllByUser($userId); if ($firstRun === 'yes' && count($userBoards) === 0) { - $this->config->setUserValue($userId,$appName,'firstRun','no'); + $this->config->setUserValue($userId, $appName, 'firstRun', 'no'); return true; } diff --git a/tests/unit/Service/DefaultBoardServiceTest.php b/tests/unit/Service/DefaultBoardServiceTest.php index dcac93ca8..0eecd8eee 100644 --- a/tests/unit/Service/DefaultBoardServiceTest.php +++ b/tests/unit/Service/DefaultBoardServiceTest.php @@ -66,11 +66,7 @@ class DefaultBoardServiceTest extends TestCase { $this->stackService = $this->createMock(StackService::class); $this->cardService = $this->createMock(CardService::class); $this->config = $this->createMock(IConfig::class); - - $this->l10n = $this->request = $this->getMockBuilder( - '\OCP\IL10n') - ->disableOriginalConstructor() - ->getMock(); + $this->l10n = $this->createMock(IL10N::class); $this->service = new DefaultBoardService( $this->l10n, @@ -83,7 +79,7 @@ class DefaultBoardServiceTest extends TestCase { } public function testCheckFirstRunCaseTrue() { - $appName = "Deck"; + $appName = 'deck'; $userBoards = []; $this->config->expects($this->once()) @@ -102,7 +98,7 @@ class DefaultBoardServiceTest extends TestCase { } public function testCheckFirstRunCaseFalse() { - $appName = "deck"; + $appName = 'deck'; $board = new Board(); $board->setTitle('Personal'); $board->setOwner($this->userId); diff --git a/tests/unit/controller/PageControllerTest.php b/tests/unit/controller/PageControllerTest.php index ce0d40b2a..f4aa70e08 100644 --- a/tests/unit/controller/PageControllerTest.php +++ b/tests/unit/controller/PageControllerTest.php @@ -59,7 +59,7 @@ class PageControllerTest extends \Test\TestCase { public function testIndexOnFirstRun() { $board = new Board(); - $board->setTitle("Personal"); + $board->setTitle('Personal'); $board->setOwner($this->userId); $board->setColor('000000'); @@ -77,7 +77,7 @@ class PageControllerTest extends \Test\TestCase { public function testIndexOnSecondRun() { - $this->config->setUserValue($this->userId,'deck','firstRun','no'); + $this->config->setUserValue($this->userId, 'deck', 'firstRun', 'no'); $this->defaultBoardService->expects($this->once()) ->method('checkFirstRun') From 3863c7497b13178bd5c7e6ce7185d9fdccca47a6 Mon Sep 17 00:00:00 2001 From: Ryan Fletcher Date: Thu, 12 Jul 2018 12:15:46 -0400 Subject: [PATCH 14/15] Used $l10n references in my unit test, this should allow it pass. Signed-off-by: Ryan Fletcher --- .../unit/Service/DefaultBoardServiceTest.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/unit/Service/DefaultBoardServiceTest.php b/tests/unit/Service/DefaultBoardServiceTest.php index 0eecd8eee..0ec239b10 100644 --- a/tests/unit/Service/DefaultBoardServiceTest.php +++ b/tests/unit/Service/DefaultBoardServiceTest.php @@ -133,31 +133,31 @@ class DefaultBoardServiceTest extends TestCase { ->willReturn($board); $stackToDoId = '123'; - $stackToDo = $this->assembleTestStack('To do', $stackToDoId, $boardId); + $stackToDo = $this->assembleTestStack($this->l10n->t('To do'), $stackToDoId, $boardId); $stackDoingId = '124'; - $stackDoing = $this->assembleTestStack('Doing', $stackDoingId, $boardId); + $stackDoing = $this->assembleTestStack($this->l10n->t('Doing'), $stackDoingId, $boardId); $stackDoneId = '125'; - $stackDone = $this->assembleTestStack('Done', $stackDoneId, $boardId); + $stackDone = $this->assembleTestStack($this->l10n->t('Done'), $stackDoneId, $boardId); $this->stackService->expects($this->exactly(3)) ->method('create') ->withConsecutive( - ['To do', $boardId, 1], - ['Doing', $boardId, 1], - ['Done', $boardId, 1] + [$this->l10n->t('To do'), $boardId, 1], + [$this->l10n->t('Doing'), $boardId, 1], + [$this->l10n->t('Done'), $boardId, 1] ) ->willReturnOnConsecutiveCalls($stackToDo, $stackDoing, $stackDone); - $cardExampleTask3 = $this->assembleTestCard('Example Task 3', $stackToDoId, $this->userId); - $cardExampleTask2 = $this->assembleTestCard('Example Task 2', $stackDoingId, $this->userId); - $cardExampleTask1 = $this->assembleTestCard('Example Task 1', $stackDoneId, $this->userId); + $cardExampleTask3 = $this->assembleTestCard($this->l10n->t('Example Task 3'), $stackToDoId, $this->userId); + $cardExampleTask2 = $this->assembleTestCard($this->l10n->t('Example Task 2'), $stackDoingId, $this->userId); + $cardExampleTask1 = $this->assembleTestCard($this->l10n->t('Example Task 1'), $stackDoneId, $this->userId); $this->cardService->expects($this->exactly(3)) ->method('create') ->withConsecutive( - ['Example Task 3', $stackToDoId, 'text', 0, $this->userId], - ['Example Task 2', $stackDoingId, 'text', 0, $this->userId], - ['Example Task 1', $stackDoneId, 'text', 0, $this->userId] + [$this->l10n->t('Example Task 3'), $stackToDoId, 'text', 0, $this->userId], + [$this->l10n->t('Example Task 2'), $stackDoingId, 'text', 0, $this->userId], + [$this->l10n->t('Example Task 1'), $stackDoneId, 'text', 0, $this->userId] ) ->willReturnonConsecutiveCalls($cardExampleTask3, $cardExampleTask2, $cardExampleTask1); From 04cb5f656ddfb098e762902ca9a814e0a6876aef Mon Sep 17 00:00:00 2001 From: Ryan Fletcher Date: Fri, 13 Jul 2018 08:53:21 -0400 Subject: [PATCH 15/15] Mocked up $this->l10n calls in DefaultBoardServiceTest Signed-off-by: Ryan Fletcher --- .../unit/Service/DefaultBoardServiceTest.php | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/unit/Service/DefaultBoardServiceTest.php b/tests/unit/Service/DefaultBoardServiceTest.php index 0ec239b10..ecabdfb61 100644 --- a/tests/unit/Service/DefaultBoardServiceTest.php +++ b/tests/unit/Service/DefaultBoardServiceTest.php @@ -132,14 +132,18 @@ class DefaultBoardServiceTest extends TestCase { ->method('create') ->willReturn($board); + $this->l10n->expects($this->any()) + ->method('t') + ->willReturnCallback(function($text) { return $text; }); + $stackToDoId = '123'; - $stackToDo = $this->assembleTestStack($this->l10n->t('To do'), $stackToDoId, $boardId); + $stackToDo = $this->assembleTestStack('To do', $stackToDoId, $boardId); $stackDoingId = '124'; - $stackDoing = $this->assembleTestStack($this->l10n->t('Doing'), $stackDoingId, $boardId); + $stackDoing = $this->assembleTestStack('Doing', $stackDoingId, $boardId); $stackDoneId = '125'; - $stackDone = $this->assembleTestStack($this->l10n->t('Done'), $stackDoneId, $boardId); + $stackDone = $this->assembleTestStack('Done', $stackDoneId, $boardId); $this->stackService->expects($this->exactly(3)) ->method('create') ->withConsecutive( @@ -149,15 +153,15 @@ class DefaultBoardServiceTest extends TestCase { ) ->willReturnOnConsecutiveCalls($stackToDo, $stackDoing, $stackDone); - $cardExampleTask3 = $this->assembleTestCard($this->l10n->t('Example Task 3'), $stackToDoId, $this->userId); - $cardExampleTask2 = $this->assembleTestCard($this->l10n->t('Example Task 2'), $stackDoingId, $this->userId); - $cardExampleTask1 = $this->assembleTestCard($this->l10n->t('Example Task 1'), $stackDoneId, $this->userId); + $cardExampleTask3 = $this->assembleTestCard('Example Task 3', $stackToDoId, $this->userId); + $cardExampleTask2 = $this->assembleTestCard('Example Task 2', $stackDoingId, $this->userId); + $cardExampleTask1 = $this->assembleTestCard('Example Task 1', $stackDoneId, $this->userId); $this->cardService->expects($this->exactly(3)) ->method('create') ->withConsecutive( - [$this->l10n->t('Example Task 3'), $stackToDoId, 'text', 0, $this->userId], - [$this->l10n->t('Example Task 2'), $stackDoingId, 'text', 0, $this->userId], - [$this->l10n->t('Example Task 1'), $stackDoneId, 'text', 0, $this->userId] + ['Example Task 3', $stackToDoId, 'text', 0, $this->userId], + ['Example Task 2', $stackDoingId, 'text', 0, $this->userId], + ['Example Task 1', $stackDoneId, 'text', 0, $this->userId] ) ->willReturnonConsecutiveCalls($cardExampleTask3, $cardExampleTask2, $cardExampleTask1);