-
Notifications
You must be signed in to change notification settings - Fork 310
Add default board #527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+340
−6
Merged
Add default board #527
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e208fd8
First Attempt at implementing createDefaultBoard()
683354d
corrected null errors from first attempt.
a36dfcc
first attempt at writing the checkFirstRun() in DefaultBoardService.php
8a8cffc
Completed checkFirstRun() in DefaultBoardService.php
61fb68f
Added a unit test against DefaultBoardService->TestCreateDefaultBoard()
e07fc0a
Corrected missing import and missing parameter in defaultBoardService…
712ab9e
Corrected testCreateDefaultBoard()
08f9874
Updated constructor in PageControllerTest
2002841
Wrote unit tests for checkFirstRun method in the default board service
be8a347
Updated PageControllerTest.php to reflect new changes
ba378ea
First attempt at using l10n
af92da9
Removing translations I attempted to put in before knowing the process.
8d4dbd4
Fixed up code styles as per review by juliushaertl
3863c74
Used $l10n references in my unit test, this should allow it pass.
04cb5f6
Mocked up $this->l10n calls in DefaultBoardServiceTest
3163563
Merge branch 'master' into issue_197
juliusknorr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,6 +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" | ||
| "Create a new board" : "Create a new board" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
| },"pluralForm" :"nplurals=2; plural=(n != 1);" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| <?php | ||
| /** | ||
| * @copyright Copyright (c) 2018 Ryan Fletcher <ryan.fletcher@codepassion.ca> | ||
| * | ||
| * @author Ryan Fletcher <ryan.fletcher@codepassion.ca> | ||
| * | ||
| * @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 <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| namespace OCA\Deck\Service; | ||
|
|
||
| use OCA\Deck\Db\BoardMapper; | ||
| use OCA\Deck\Service\BoardService; | ||
| use OCA\Deck\Service\StackService; | ||
| use OCA\Deck\Service\CardService; | ||
| use OCP\IConfig; | ||
| use OCP\IL10N; | ||
|
|
||
| class DefaultBoardService { | ||
|
|
||
| private $boardMapper; | ||
| private $boardService; | ||
| private $stackService; | ||
| private $cardService; | ||
| private $config; | ||
| private $l10n; | ||
|
|
||
| public function __construct( | ||
| IL10N $l10n, | ||
| BoardMapper $boardMapper, | ||
| BoardService $boardService, | ||
| StackService $stackService, | ||
| CardService $cardService, | ||
| IConfig $config | ||
| ) { | ||
|
|
||
| $this->boardService = $boardService; | ||
| $this->stackService = $stackService; | ||
| $this->cardService = $cardService; | ||
| $this->config = $config; | ||
| $this->boardMapper = $boardMapper; | ||
| $this->l10n = $l10n; | ||
| } | ||
|
|
||
| public function checkFirstRun($userId, $appName) { | ||
| $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; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| public function createDefaultBoard($title, $userId, $color) { | ||
| $defaultBoard = $this->boardService->create($title, $userId, $color); | ||
| $defaultStacks = []; | ||
| $defaultCards = []; | ||
|
|
||
| $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($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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| <?php | ||
| /** | ||
| * @copyright Copyright (c) 2018 Ryan Fletcher <ryan.fletcher@codepassion.ca> | ||
| * | ||
| * @author Ryan Fletcher <ryan.fletcher@codepassion.ca> | ||
| * | ||
| * @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 <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| 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; | ||
| use OCP\IL10N; | ||
| use \Test\TestCase; | ||
|
|
||
| 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 $l10n; | ||
|
|
||
| private $userId = 'admin'; | ||
|
|
||
| public function 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->l10n = $this->createMock(IL10N::class); | ||
|
|
||
| $this->service = new DefaultBoardService( | ||
| $this->l10n, | ||
| $this->boardMapper, | ||
| $this->boardService, | ||
| $this->stackService, | ||
| $this->cardService, | ||
| $this->config | ||
| ); | ||
| } | ||
|
|
||
| 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'; | ||
| $boardId = 5; | ||
|
|
||
| $board = new Board(); | ||
| $board->setId($boardId); | ||
| $board->setTitle($title); | ||
| $board->setOwner($this->userId); | ||
| $board->setColor($color); | ||
| $this->boardService->expects($this->once()) | ||
| ->method('create') | ||
| ->willReturn($board); | ||
|
|
||
| $this->l10n->expects($this->any()) | ||
| ->method('t') | ||
| ->willReturnCallback(function($text) { return $text; }); | ||
|
|
||
| $stackToDoId = '123'; | ||
| $stackToDo = $this->assembleTestStack('To do', $stackToDoId, $boardId); | ||
|
|
||
| $stackDoingId = '124'; | ||
| $stackDoing = $this->assembleTestStack('Doing', $stackDoingId, $boardId); | ||
|
|
||
| $stackDoneId = '125'; | ||
| $stackDone = $this->assembleTestStack('Done', $stackDoneId, $boardId); | ||
| $this->stackService->expects($this->exactly(3)) | ||
| ->method('create') | ||
| ->withConsecutive( | ||
| [$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); | ||
| $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] | ||
| ) | ||
| ->willReturnonConsecutiveCalls($cardExampleTask3, $cardExampleTask2, $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->setOwner($userId); | ||
|
|
||
| return $card; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change can be removed as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this string part of the l10n definitions? I see it in every other file, all I did here was remove the comma I appended at the end of the line, and obvious I accidentally added in some extra white space.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was referring to the whitespace 😉 But that's a non-blocker.