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