Move default board creation to Application and cleanup code

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2020-01-26 12:14:51 +01:00
parent ef986842a5
commit bdc149aa6b
7 changed files with 134 additions and 163 deletions

View File

@@ -21,15 +21,19 @@
* *
*/ */
if ((@include_once __DIR__ . '/../vendor/autoload.php')===false) { use OCA\Deck\AppInfo\Application;
use OCP\AppFramework\QueryException;
if ((@include_once __DIR__ . '/../vendor/autoload.php')=== false) {
throw new Exception('Cannot include autoload. Did you run install dependencies using composer?'); throw new Exception('Cannot include autoload. Did you run install dependencies using composer?');
} }
$app = \OC::$server->query(\OCA\Deck\AppInfo\Application::class); try {
$app->registerNavigationEntry(); /** @var Application $app */
$app->registerNotifications(); $app = \OC::$server->query(Application::class);
$app->registerCommentsEntity(); $app->register();
$app->registerFullTextSearch(); } catch (QueryException $e) {
}
/** Load activity style global so it is availabile in the activity app as well */ /** Load activity style global so it is availabile in the activity app as well */
\OC_Util::addStyle('deck', 'activity'); \OC_Util::addStyle('deck', 'activity');

View File

@@ -24,29 +24,42 @@
namespace OCA\Deck\AppInfo; namespace OCA\Deck\AppInfo;
use Exception; use Exception;
use InvalidArgumentException;
use OC_Util;
use OCA\Deck\Activity\CommentEventHandler; use OCA\Deck\Activity\CommentEventHandler;
use OCA\Deck\Capabilities; use OCA\Deck\Capabilities;
use OCA\Deck\Collaboration\Resources\ResourceProvider;
use OCA\Deck\Collaboration\Resources\ResourceProviderCard;
use OCA\Deck\Db\Acl; use OCA\Deck\Db\Acl;
use OCA\Deck\Db\AclMapper; use OCA\Deck\Db\AclMapper;
use OCA\Deck\Db\AssignedUsersMapper; use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\CardMapper;
use OCA\Deck\Middleware\ExceptionMiddleware; use OCA\Deck\Middleware\ExceptionMiddleware;
use OCA\Deck\Notification\Notifier; use OCA\Deck\Notification\Notifier;
use OCA\Deck\Service\DefaultBoardService;
use OCA\Deck\Service\FullTextSearchService; use OCA\Deck\Service\FullTextSearchService;
use OCA\Deck\Service\PermissionService;
use OCP\AppFramework\App; use OCP\AppFramework\App;
use OCP\Collaboration\Resources\IManager; use OCP\Collaboration\Resources\IManager;
use OCP\Collaboration\Resources\IProviderManager;
use OCP\Comments\CommentsEntityEvent; use OCP\Comments\CommentsEntityEvent;
use OCP\FullTextSearch\IFullTextSearchManager; use OCP\FullTextSearch\IFullTextSearchManager;
use OCP\IGroup; use OCP\IGroup;
use OCP\ILogger;
use OCP\IServerContainer;
use OCP\IUser; use OCP\IUser;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\INavigationManager; use OCP\IUserSession;
use OCP\Util; use OCP\Util;
use Symfony\Component\EventDispatcher\GenericEvent; use Symfony\Component\EventDispatcher\GenericEvent;
class Application extends App { class Application extends App {
public const APP_ID = 'deck';
/** @var IServerContainer */
private $server;
/** @var FullTextSearchService */ /** @var FullTextSearchService */
private $fullTextSearchService; private $fullTextSearchService;
@@ -54,40 +67,60 @@ class Application extends App {
/** @var IFullTextSearchManager */ /** @var IFullTextSearchManager */
private $fullTextSearchManager; private $fullTextSearchManager;
/** @var ILogger */
private $logger;
/**
* Application constructor.
*
* @param array $urlParams
*
* @throws \OCP\AppFramework\QueryException
*/
public function __construct(array $urlParams = array()) { public function __construct(array $urlParams = array()) {
parent::__construct('deck', $urlParams); parent::__construct('deck', $urlParams);
$container = $this->getContainer(); $container = $this->getContainer();
$server = $container->getServer(); $server = $this->getContainer()->getServer();
$container->registerService('ExceptionMiddleware', function() use ($server) { $this->server = $server;
return new ExceptionMiddleware( $this->logger = $server->getLogger();
$server->getLogger(),
$server->getConfig() $container->registerCapability(Capabilities::class);
); $container->registerMiddleWare(ExceptionMiddleware::class);
$container->registerService('databaseType', static function() use ($server) {
return $server->getConfig()->getSystemValue('dbtype', 'sqlite');
}); });
$container->registerMiddleWare('ExceptionMiddleware'); $container->registerService('database4ByteSupport', static function() use ($server) {
return $server->getDatabaseConnection()->supports4ByteText();
$container->registerService('databaseType', function($container) {
return $container->getServer()->getConfig()->getSystemValue('dbtype', 'sqlite');
}); });
$container->registerService('database4ByteSupport', function($container) { }
return $container->getServer()->getDatabaseConnection()->supports4ByteText();
});
public function register(): void {
$this->registerNavigationEntry();
$this->registerUserGroupHooks();
$this->registerNotifications();
$this->registerCommentsEntity();
$this->registerFullTextSearch();
$this->registerCollaborationResources();
$this->checkDefaultBoard();
}
public function registerNavigationEntry(): void {
$container = $this->getContainer();
$this->server->getNavigationManager()->add(static function() use ($container) {
$urlGenerator = $container->query(IURLGenerator::class);
return [
'id' => 'deck',
'order' => 10,
'href' => $urlGenerator->linkToRoute('deck.page.index'),
'icon' => $urlGenerator->imagePath('deck', 'deck.svg'),
'name' => 'Deck',
];
});
}
private function registerUserGroupHooks(): void {
$container = $this->getContainer();
// Delete user/group acl entries when they get deleted // Delete user/group acl entries when they get deleted
/** @var IUserManager $userManager */ /** @var IUserManager $userManager */
$userManager = $server->getUserManager(); $userManager = $this->server->getUserManager();
$userManager->listen('\OC\User', 'postDelete', function(IUser $user) use ($container) { $userManager->listen('\OC\User', 'postDelete', static function(IUser $user) use ($container) {
// delete existing acl entries for deleted user // delete existing acl entries for deleted user
/** @var AclMapper $aclMapper */ /** @var AclMapper $aclMapper */
$aclMapper = $container->query(AclMapper::class); $aclMapper = $container->query(AclMapper::class);
@@ -104,8 +137,8 @@ class Application extends App {
}); });
/** @var IUserManager $userManager */ /** @var IUserManager $userManager */
$groupManager = $server->getGroupManager(); $groupManager = $this->server->getGroupManager();
$groupManager->listen('\OC\Group', 'postDelete', function(IGroup $group) use ($container) { $groupManager->listen('\OC\Group', 'postDelete', static function(IGroup $group) use ($container) {
/** @var AclMapper $aclMapper */ /** @var AclMapper $aclMapper */
$aclMapper = $container->query(AclMapper::class); $aclMapper = $container->query(AclMapper::class);
$aclMapper->findByParticipant(Acl::PERMISSION_TYPE_GROUP, $group->getGID()); $aclMapper->findByParticipant(Acl::PERMISSION_TYPE_GROUP, $group->getGID());
@@ -114,47 +147,21 @@ class Application extends App {
$aclMapper->delete($acl); $aclMapper->delete($acl);
} }
}); });
$this->registerCollaborationResources();
$this->getContainer()->registerCapability(Capabilities::class);
} }
/** public function registerNotifications(): void {
* @throws \OCP\AppFramework\QueryException $notificationManager = $this->server->getNotificationManager();
*/
public function registerNavigationEntry() {
$container = $this->getContainer();
$container->query(INavigationManager::class)->add(function() use ($container) {
$urlGenerator = $container->query(IURLGenerator::class);
return [
'id' => 'deck',
'order' => 10,
'href' => $urlGenerator->linkToRoute('deck.page.index'),
'icon' => $urlGenerator->imagePath('deck', 'deck.svg'),
'name' => 'Deck',
];
});
}
public function registerNotifications() {
$notificationManager = \OC::$server->getNotificationManager();
$notificationManager->registerNotifierService(Notifier::class); $notificationManager->registerNotifierService(Notifier::class);
} }
/** public function registerCommentsEntity(): void {
* @throws \OCP\AppFramework\QueryException $this->server->getEventDispatcher()->addListener(CommentsEntityEvent::EVENT_ENTITY, function(CommentsEntityEvent $event) {
*/
public function registerCommentsEntity() {
$this->getContainer()->getServer()->getEventDispatcher()->addListener(CommentsEntityEvent::EVENT_ENTITY, function(CommentsEntityEvent $event) {
$event->addEntityCollection('deckCard', function($name) { $event->addEntityCollection('deckCard', function($name) {
/** @var CardMapper */ /** @var CardMapper */
$service = $this->getContainer()->query(CardMapper::class); $service = $this->getContainer()->query(CardMapper::class);
try { try {
$service->find((int) $name); $service->find((int) $name);
} catch (\InvalidArgumentException $e) { } catch (InvalidArgumentException $e) {
return false; return false;
} }
return true; return true;
@@ -164,19 +171,15 @@ class Application extends App {
} }
/** /**
* @throws \OCP\AppFramework\QueryException
*/ */
protected function registerCommentsEventHandler() { protected function registerCommentsEventHandler(): void {
$this->getContainer()->getServer()->getCommentsManager()->registerEventHandler(function () { $this->server->getCommentsManager()->registerEventHandler(function () {
return $this->getContainer()->query(CommentEventHandler::class); return $this->getContainer()->query(CommentEventHandler::class);
}); });
} }
/** protected function registerCollaborationResources(): void {
* @throws \OCP\AppFramework\QueryException $version = OC_Util::getVersion()[0];
*/
protected function registerCollaborationResources() {
$version = \OC_Util::getVersion()[0];
if ($version < 16) { if ($version < 16) {
return; return;
} }
@@ -190,18 +193,18 @@ class Application extends App {
/** @var IManager $resourceManager */ /** @var IManager $resourceManager */
$resourceManager = $this->getContainer()->query(IManager::class); $resourceManager = $this->getContainer()->query(IManager::class);
} else { } else {
/** @var \OCP\Collaboration\Resources\IProviderManager $resourceManager */ /** @var IProviderManager $resourceManager */
$resourceManager = $this->getContainer()->query(\OCP\Collaboration\Resources\IProviderManager::class); $resourceManager = $this->getContainer()->query(IProviderManager::class);
} }
$resourceManager->registerResourceProvider(\OCA\Deck\Collaboration\Resources\ResourceProvider::class); $resourceManager->registerResourceProvider(ResourceProvider::class);
$resourceManager->registerResourceProvider(\OCA\Deck\Collaboration\Resources\ResourceProviderCard::class); $resourceManager->registerResourceProvider(ResourceProviderCard::class);
\OC::$server->getEventDispatcher()->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function () { $this->server->getEventDispatcher()->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', static function () {
\OCP\Util::addScript('deck', 'collections'); Util::addScript('deck', 'collections');
}); });
} }
public function registerFullTextSearch() { public function registerFullTextSearch(): void {
if (Util::getVersion()[0] < 16) { if (Util::getVersion()[0] < 16) {
return; return;
} }
@@ -218,7 +221,7 @@ class Application extends App {
return; return;
} }
$eventDispatcher = \OC::$server->getEventDispatcher(); $eventDispatcher = $this->server->getEventDispatcher();
$eventDispatcher->addListener( $eventDispatcher->addListener(
'\OCA\Deck\Card::onCreate', function(GenericEvent $e) { '\OCA\Deck\Card::onCreate', function(GenericEvent $e) {
$this->fullTextSearchService->onCardCreated($e); $this->fullTextSearchService->onCardCreated($e);
@@ -251,4 +254,19 @@ class Application extends App {
); );
} }
private function checkDefaultBoard(): void {
try {
/** @var IUserSession $userSession */
$userSession = $this->getContainer()->query(IUserSession::class);
$userId = $userSession->getUser() ? $userSession->getUser()->getUID() : null;
/** @var DefaultBoardService $defaultBoardService */
$defaultBoardService = $this->getContainer()->query(DefaultBoardService::class);
$permissionService = $this->getContainer()->query(PermissionService::class);
if ($userId !== null && $defaultBoardService->checkFirstRun($userId) && $permissionService->canCreate()) {
$defaultBoardService->createDefaultBoard($this->server->getL10N(self::APP_ID)->t('Personal'), $userId, '0087C5');
}
} catch (\Throwable $e) {
$this->logger->logException($e);
}
}
} }

View File

@@ -23,7 +23,6 @@
namespace OCA\Deck\Controller; namespace OCA\Deck\Controller;
use OCA\Deck\Service\DefaultBoardService;
use OCA\Deck\Service\PermissionService; use OCA\Deck\Service\PermissionService;
use OCP\IRequest; use OCP\IRequest;
use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\TemplateResponse;
@@ -32,7 +31,6 @@ use OCP\IL10N;
class PageController extends Controller { class PageController extends Controller {
private $defaultBoardService;
private $permissionService; private $permissionService;
private $userId; private $userId;
private $l10n; private $l10n;
@@ -40,7 +38,6 @@ class PageController extends Controller {
public function __construct( public function __construct(
$AppName, $AppName,
IRequest $request, IRequest $request,
DefaultBoardService $defaultBoardService,
PermissionService $permissionService, PermissionService $permissionService,
IL10N $l10n, IL10N $l10n,
$userId $userId
@@ -48,7 +45,6 @@ class PageController extends Controller {
parent::__construct($AppName, $request); parent::__construct($AppName, $request);
$this->userId = $userId; $this->userId = $userId;
$this->defaultBoardService = $defaultBoardService;
$this->permissionService = $permissionService; $this->permissionService = $permissionService;
$this->l10n = $l10n; $this->l10n = $l10n;
} }
@@ -67,12 +63,6 @@ class PageController extends Controller {
'canCreate' => $this->permissionService->canCreate() 'canCreate' => $this->permissionService->canCreate()
]; ];
if ($this->defaultBoardService->checkFirstRun($this->userId, $this->appName)) {
if ($this->permissionService->canCreate()) {
$this->defaultBoardService->createDefaultBoard($this->l10n->t('Personal'), $this->userId, '0087C5');
}
}
return new TemplateResponse('deck', 'main', $params); return new TemplateResponse('deck', 'main', $params);
} }

View File

@@ -134,10 +134,10 @@ class BoardService {
} }
$permissions = $this->permissionService->matchPermissions($item); $permissions = $this->permissionService->matchPermissions($item);
$item->setPermissions([ $item->setPermissions([
'PERMISSION_READ' => $permissions[Acl::PERMISSION_READ], 'PERMISSION_READ' => $permissions[Acl::PERMISSION_READ] ?? false,
'PERMISSION_EDIT' => $permissions[Acl::PERMISSION_EDIT], 'PERMISSION_EDIT' => $permissions[Acl::PERMISSION_EDIT] ?? false,
'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE], 'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE] ?? false,
'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE] 'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE] ?? false
]); ]);
$result[$item->getId()] = $item; $result[$item->getId()] = $item;
} }
@@ -170,10 +170,10 @@ class BoardService {
} }
$permissions = $this->permissionService->matchPermissions($board); $permissions = $this->permissionService->matchPermissions($board);
$board->setPermissions([ $board->setPermissions([
'PERMISSION_READ' => $permissions[Acl::PERMISSION_READ], 'PERMISSION_READ' => $permissions[Acl::PERMISSION_READ] ?? false,
'PERMISSION_EDIT' => $permissions[Acl::PERMISSION_EDIT], 'PERMISSION_EDIT' => $permissions[Acl::PERMISSION_EDIT] ?? false,
'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE], 'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE] ?? false,
'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE] 'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE] ?? false
]); ]);
$this->enrichWithUsers($board); $this->enrichWithUsers($board);
return $board; return $board;
@@ -307,10 +307,10 @@ class BoardService {
$this->boardMapper->mapOwner($new_board); $this->boardMapper->mapOwner($new_board);
$permissions = $this->permissionService->matchPermissions($new_board); $permissions = $this->permissionService->matchPermissions($new_board);
$new_board->setPermissions([ $new_board->setPermissions([
'PERMISSION_READ' => $permissions[Acl::PERMISSION_READ], 'PERMISSION_READ' => $permissions[Acl::PERMISSION_READ] ?? false,
'PERMISSION_EDIT' => $permissions[Acl::PERMISSION_EDIT], 'PERMISSION_EDIT' => $permissions[Acl::PERMISSION_EDIT] ?? false,
'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE], 'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE] ?? false,
'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE] 'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE] ?? false
]); ]);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $new_board, ActivityManager::SUBJECT_BOARD_CREATE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $new_board, ActivityManager::SUBJECT_BOARD_CREATE);
$this->changeHelper->boardChanged($new_board->getId()); $this->changeHelper->boardChanged($new_board->getId());
@@ -630,7 +630,7 @@ class BoardService {
} }
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_READ); $this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_READ);
$board = $this->boardMapper->find($id); $board = $this->boardMapper->find($id);
$newBoard = new Board(); $newBoard = new Board();
$newBoard->setTitle($board->getTitle() . ' (' . $this->l10n->t('copy') . ')'); $newBoard->setTitle($board->getTitle() . ' (' . $this->l10n->t('copy') . ')');
@@ -654,7 +654,7 @@ class BoardService {
$newStack->setBoardId($newBoard->getId()); $newStack->setBoardId($newBoard->getId());
$this->stackMapper->insert($newStack); $this->stackMapper->insert($newStack);
} }
return $newBoard; return $newBoard;
} }

View File

@@ -23,13 +23,12 @@
namespace OCA\Deck\Service; namespace OCA\Deck\Service;
use OCA\Deck\AppInfo\Application;
use OCA\Deck\Db\BoardMapper; 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\IConfig;
use OCP\IL10N; use OCP\IL10N;
use OCA\Deck\BadRequestException; use OCA\Deck\BadRequestException;
use OCP\PreConditionNotMetException;
class DefaultBoardService { class DefaultBoardService {
@@ -58,17 +57,21 @@ class DefaultBoardService {
} }
/** /**
* Return true if this is the first time a user is acessing their instance with deck enabled
*
* @param $userId * @param $userId
* @param $appName
* @return bool * @return bool
* @throws \OCP\PreConditionNotMetException
*/ */
public function checkFirstRun($userId, $appName) { public function checkFirstRun($userId): bool {
$firstRun = $this->config->getUserValue($userId, $appName, 'firstRun', 'yes'); $firstRun = $this->config->getUserValue($userId, Application::APP_ID, 'firstRun', 'yes');
$userBoards = $this->boardMapper->findAllByUser($userId); $userBoards = $this->boardMapper->findAllByUser($userId);
if ($firstRun === 'yes' && count($userBoards) === 0) { if ($firstRun === 'yes' && count($userBoards) === 0) {
$this->config->setUserValue($userId, $appName, 'firstRun', 'no'); try {
$this->config->setUserValue($userId, Application::APP_ID, 'firstRun', 'no');
} catch (PreConditionNotMetException $e) {
return false;
}
return true; return true;
} }
@@ -86,7 +89,7 @@ class DefaultBoardService {
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws BadRequestException * @throws BadRequestException
*/ */
public function createDefaultBoard($title, $userId, $color) { public function createDefaultBoard(string $title, string $userId, string $color) {
if ($title === false || $title === null) { if ($title === false || $title === null) {
throw new BadRequestException('title must be provided'); throw new BadRequestException('title must be provided');
@@ -104,16 +107,16 @@ class DefaultBoardService {
$defaultStacks = []; $defaultStacks = [];
$defaultCards = []; $defaultCards = [];
$boardId = $defaultBoard->getId(); $boardId = $defaultBoard->getId();
$defaultStacks[] = $this->stackService->create($this->l10n->t('To do'), $boardId, 1); $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('Doing'), $boardId, 1);
$defaultStacks[] = $this->stackService->create($this->l10n->t('Done'), $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 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 2'), $defaultStacks[1]->getId(), 'text', 0, $userId);
$defaultCards[] = $this->cardService->create($this->l10n->t('Example Task 1'), $defaultStacks[2]->getId(), 'text', 0, $userId); $defaultCards[] = $this->cardService->create($this->l10n->t('Example Task 1'), $defaultStacks[2]->getId(), 'text', 0, $userId);
return $defaultBoard; return $defaultBoard;
} }
} }

View File

@@ -94,7 +94,7 @@ class DefaultBoardServiceTest extends TestCase {
$this->config->expects($this->once()) $this->config->expects($this->once())
->method('setUserValue'); ->method('setUserValue');
$result = $this->service->checkFirstRun($this->userId, $appName); $result = $this->service->checkFirstRun($this->userId);
$this->assertEquals($result, true); $this->assertEquals($result, true);
} }
@@ -115,7 +115,7 @@ class DefaultBoardServiceTest extends TestCase {
->method('findAllByUser') ->method('findAllByUser')
->willReturn($userBoards); ->willReturn($userBoards);
$result = $this->service->checkFirstRun($this->userId, $appName); $result = $this->service->checkFirstRun($this->userId);
$this->assertEquals($result, false); $this->assertEquals($result, false);
} }

View File

@@ -45,69 +45,25 @@ class PageControllerTest extends \Test\TestCase {
public function setUp(): void { public function setUp(): void {
$this->l10n = $this->createMock(IL10N::class); $this->l10n = $this->createMock(IL10N::class);
$this->request = $this->createMock(IRequest::class); $this->request = $this->createMock(IRequest::class);
$this->defaultBoardService = $this->createMock(DefaultBoardService::class);
$this->permissionService = $this->createMock(PermissionService::class); $this->permissionService = $this->createMock(PermissionService::class);
$this->config = $this->createMock(IConfig::class); $this->config = $this->createMock(IConfig::class);
$this->controller = new PageController( $this->controller = new PageController(
'deck', $this->request, $this->defaultBoardService, $this->permissionService, $this->l10n, $this->userId 'deck', $this->request, $this->permissionService, $this->l10n, $this->userId
); );
} }
public function testIndexOnFirstRun() { public function testIndex() {
$board = new Board(); $board = new Board();
$board->setTitle('Personal'); $board->setTitle('Personal');
$board->setOwner($this->userId); $board->setOwner($this->userId);
$board->setColor('317CCC'); $board->setColor('317CCC');
$this->defaultBoardService->expects($this->once())
->method('checkFirstRun')
->willReturn(true);
$this->permissionService->expects($this->any()) $this->permissionService->expects($this->any())
->method('canCreate') ->method('canCreate')
->willReturn(true); ->willReturn(true);
$this->defaultBoardService->expects($this->once())
->method('createDefaultBoard')
->willReturn($board);
$response = $this->controller->index();
$this->assertEquals('main', $response->getTemplateName());
}
public function testIndexOnFirstRunNoCreate() {
$board = new Board();
$board->setTitle('Personal');
$board->setOwner($this->userId);
$board->setColor('317CCC');
$this->defaultBoardService->expects($this->once())
->method('checkFirstRun')
->willReturn(true);
$this->permissionService->expects($this->any())
->method('canCreate')
->willReturn(false);
$this->defaultBoardService->expects($this->never())
->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);
$response = $this->controller->index(); $response = $this->controller->index();
$this->assertEquals('main', $response->getTemplateName()); $this->assertEquals('main', $response->getTemplateName());
} }