From 2002841c6138e4d5f89e71522f34030740c3f24c Mon Sep 17 00:00:00 2001 From: Ryan Fletcher Date: Wed, 11 Jul 2018 12:59:40 -0400 Subject: [PATCH] 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());