diff options
author | Gerardo Zamudio <gerardozamudio@users.noreply.github.com> | 2016-02-24 23:48:50 -0600 |
---|---|---|
committer | Gerardo Zamudio <gerardozamudio@users.noreply.github.com> | 2016-02-24 23:48:50 -0600 |
commit | e4de6b3898b64b26d29aff31f21df5fda8055686 (patch) | |
tree | 575f8a65440f291d70a070d168eafca8c82a6459 /tests/units/Helper | |
parent | d9ffbea174ea6524d0a22f8375ca8b3aa04a3c96 (diff) | |
parent | a6540bc604c837d92c9368540c145606723e97f7 (diff) |
Merge pull request #1 from fguillot/master
Update from upstream
Diffstat (limited to 'tests/units/Helper')
-rw-r--r-- | tests/units/Helper/AppHelperTest.php | 10 | ||||
-rw-r--r-- | tests/units/Helper/AssetHelperTest.php | 1 | ||||
-rw-r--r-- | tests/units/Helper/DatetimeHelperTest.php | 52 | ||||
-rw-r--r-- | tests/units/Helper/FileHelperText.php | 27 | ||||
-rw-r--r-- | tests/units/Helper/TaskHelperTest.php | 32 | ||||
-rw-r--r-- | tests/units/Helper/TextHelperTest.php | 8 | ||||
-rw-r--r-- | tests/units/Helper/UrlHelperTest.php | 80 | ||||
-rw-r--r-- | tests/units/Helper/UserHelperTest.php | 310 |
8 files changed, 345 insertions, 175 deletions
diff --git a/tests/units/Helper/AppHelperTest.php b/tests/units/Helper/AppHelperTest.php index cbd8b8ab..0639b7aa 100644 --- a/tests/units/Helper/AppHelperTest.php +++ b/tests/units/Helper/AppHelperTest.php @@ -2,7 +2,7 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Core\Session; +use Kanboard\Core\Session\FlashMessage; use Kanboard\Helper\App; use Kanboard\Model\Config; @@ -23,15 +23,15 @@ class AppHelperTest extends Base public function testFlashMessage() { $h = new App($this->container); - $s = new Session; + $f = new FlashMessage($this->container); $this->assertEmpty($h->flashMessage()); - $s->flash('test & test'); + + $f->success('test & test'); $this->assertEquals('<div class="alert alert-success alert-fade-out">test & test</div>', $h->flashMessage()); $this->assertEmpty($h->flashMessage()); - $this->assertEmpty($h->flashMessage()); - $s->flashError('test & test'); + $f->failure('test & test'); $this->assertEquals('<div class="alert alert-error">test & test</div>', $h->flashMessage()); $this->assertEmpty($h->flashMessage()); } diff --git a/tests/units/Helper/AssetHelperTest.php b/tests/units/Helper/AssetHelperTest.php index 7e1edb12..64fcd569 100644 --- a/tests/units/Helper/AssetHelperTest.php +++ b/tests/units/Helper/AssetHelperTest.php @@ -15,6 +15,7 @@ class AssetHelperTest extends Base $this->assertEmpty($h->customCss()); $this->assertTrue($c->save(array('application_stylesheet' => 'p { color: red }'))); + $this->container['memoryCache']->flush(); $this->assertEquals('<style>p { color: red }</style>', $h->customCss()); } diff --git a/tests/units/Helper/DatetimeHelperTest.php b/tests/units/Helper/DatetimeHelperTest.php index 8e9c461b..f27a2eb9 100644 --- a/tests/units/Helper/DatetimeHelperTest.php +++ b/tests/units/Helper/DatetimeHelperTest.php @@ -6,23 +6,45 @@ use Kanboard\Helper\Dt; class DatetimeHelperTest extends Base { + public function testGetTime() + { + $helper = new Dt($this->container); + $this->assertEquals('17:25', $helper->time(1422206700)); + } + + public function testGetDate() + { + $helper = new Dt($this->container); + $this->assertEquals('01/25/2015', $helper->date(1422206700)); + $this->assertEquals('01/25/2015', $helper->date('2015-01-25')); + $this->assertEquals('', $helper->date('0')); + $this->assertEquals('', $helper->date(0)); + $this->assertEquals('', $helper->date('')); + } + + public function testGetDatetime() + { + $helper = new Dt($this->container); + $this->assertEquals('01/25/2015 17:25', $helper->datetime(1422206700)); + } + public function testAge() { - $h = new Dt($this->container); - - $this->assertEquals('<15m', $h->age(0, 30)); - $this->assertEquals('<30m', $h->age(0, 1000)); - $this->assertEquals('<1h', $h->age(0, 3000)); - $this->assertEquals('~2h', $h->age(0, 2*3600)); - $this->assertEquals('1d', $h->age(0, 30*3600)); - $this->assertEquals('2d', $h->age(0, 65*3600)); + $helper = new Dt($this->container); + + $this->assertEquals('<15m', $helper->age(0, 30)); + $this->assertEquals('<30m', $helper->age(0, 1000)); + $this->assertEquals('<1h', $helper->age(0, 3000)); + $this->assertEquals('~2h', $helper->age(0, 2*3600)); + $this->assertEquals('1d', $helper->age(0, 30*3600)); + $this->assertEquals('2d', $helper->age(0, 65*3600)); } public function testGetDayHours() { - $h = new Dt($this->container); + $helper = new Dt($this->container); - $slots = $h->getDayHours(); + $slots = $helper->getDayHours(); $this->assertNotEmpty($slots); $this->assertCount(48, $slots); @@ -36,9 +58,9 @@ class DatetimeHelperTest extends Base public function testGetWeekDays() { - $h = new Dt($this->container); + $helper = new Dt($this->container); - $slots = $h->getWeekDays(); + $slots = $helper->getWeekDays(); $this->assertNotEmpty($slots); $this->assertCount(7, $slots); @@ -48,9 +70,9 @@ class DatetimeHelperTest extends Base public function testGetWeekDay() { - $h = new Dt($this->container); + $helper = new Dt($this->container); - $this->assertEquals('Monday', $h->getWeekDay(1)); - $this->assertEquals('Sunday', $h->getWeekDay(7)); + $this->assertEquals('Monday', $helper->getWeekDay(1)); + $this->assertEquals('Sunday', $helper->getWeekDay(7)); } } diff --git a/tests/units/Helper/FileHelperText.php b/tests/units/Helper/FileHelperText.php index a681c890..6a1b78a4 100644 --- a/tests/units/Helper/FileHelperText.php +++ b/tests/units/Helper/FileHelperText.php @@ -8,8 +8,29 @@ class FileHelperTest extends Base { public function testIcon() { - $h = new File($this->container); - $this->assertEquals('fa-file-image-o', $h->icon('test.png')); - $this->assertEquals('fa-file-o', $h->icon('test')); + $helper = new File($this->container); + $this->assertEquals('fa-file-image-o', $helper->icon('test.png')); + $this->assertEquals('fa-file-o', $helper->icon('test')); + } + + public function testGetMimeType() + { + $helper = new File($this->container); + + $this->assertEquals('image/jpeg', $helper->getImageMimeType('My File.JPG')); + $this->assertEquals('image/jpeg', $helper->getImageMimeType('My File.jpeg')); + $this->assertEquals('image/png', $helper->getImageMimeType('My File.PNG')); + $this->assertEquals('image/gif', $helper->getImageMimeType('My File.gif')); + $this->assertEquals('image/jpeg', $helper->getImageMimeType('My File.bmp')); + $this->assertEquals('image/jpeg', $helper->getImageMimeType('My File')); + } + + public function testGetPreviewType() + { + $helper = new File($this->container); + $this->assertEquals('text', $helper->getPreviewType('test.txt')); + $this->assertEquals('markdown', $helper->getPreviewType('test.markdown')); + $this->assertEquals('md', $helper->getPreviewType('test.md')); + $this->assertEquals(null, $helper->getPreviewType('test.doc')); } } diff --git a/tests/units/Helper/TaskHelperTest.php b/tests/units/Helper/TaskHelperTest.php new file mode 100644 index 00000000..726188e4 --- /dev/null +++ b/tests/units/Helper/TaskHelperTest.php @@ -0,0 +1,32 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Helper\Task; + +class TaskHelperTest extends Base +{ + public function testSelectPriority() + { + $helper = new Task($this->container); + $this->assertNotEmpty($helper->selectPriority(array('priority_end' => '3', 'priority_start' => '1', 'priority_default' => '2'), array())); + $this->assertEmpty($helper->selectPriority(array('priority_end' => '3', 'priority_start' => '3', 'priority_default' => '2'), array())); + } + + public function testFormatPriority() + { + $helper = new Task($this->container); + + $this->assertEquals( + '<span class="task-board-priority" title="Task priority">P2</span>', + $helper->formatPriority(array('priority_end' => '3', 'priority_start' => '1', 'priority_default' => '2'), array('priority' => 2)) + ); + + $this->assertEquals( + '<span class="task-board-priority" title="Task priority">-P6</span>', + $helper->formatPriority(array('priority_end' => '3', 'priority_start' => '1', 'priority_default' => '2'), array('priority' => -6)) + ); + + $this->assertEmpty($helper->formatPriority(array('priority_end' => '3', 'priority_start' => '3', 'priority_default' => '2'), array())); + } +} diff --git a/tests/units/Helper/TextHelperTest.php b/tests/units/Helper/TextHelperTest.php index 30c537a9..a4bdfa91 100644 --- a/tests/units/Helper/TextHelperTest.php +++ b/tests/units/Helper/TextHelperTest.php @@ -6,7 +6,7 @@ use Kanboard\Helper\Text; class TextHelperTest extends Base { - public function testMarkdown() + public function testMarkdownTaskLink() { $h = new Text($this->container); @@ -31,6 +31,12 @@ class TextHelperTest extends Base ); } + public function testMarkdownUserLink() + { + $h = new Text($this->container); + $this->assertEquals('<p>Text <a href="?controller=user&action=profile&user_id=1" class="user-mention-link">@admin</a> @notfound</p>', $h->markdown('Text @admin @notfound')); + } + public function testFormatBytes() { $h = new Text($this->container); diff --git a/tests/units/Helper/UrlHelperTest.php b/tests/units/Helper/UrlHelperTest.php index cbacbc73..15e01237 100644 --- a/tests/units/Helper/UrlHelperTest.php +++ b/tests/units/Helper/UrlHelperTest.php @@ -4,14 +4,36 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Helper\Url; use Kanboard\Model\Config; +use Kanboard\Core\Http\Request; class UrlHelperTest extends Base { - public function testLink() + public function testPluginLink() { $h = new Url($this->container); $this->assertEquals( - '<a href="?controller=a&action=b&d=e" class="f" title="g" target="_blank">label</a>', + '<a href="?controller=a&action=b&d=e&plugin=something" class="f" title=\'g\' target="_blank">label</a>', + $h->link('label', 'a', 'b', array('d' => 'e', 'plugin' => 'something'), false, 'f', 'g', true) + ); + } + + public function testPluginLinkWithRouteDefined() + { + $this->container['route']->enable(); + $this->container['route']->addRoute('/myplugin/something/:d', 'a', 'b', 'something'); + + $h = new Url($this->container); + $this->assertEquals( + '<a href="myplugin/something/e" class="f" title=\'g\' target="_blank">label</a>', + $h->link('label', 'a', 'b', array('d' => 'e', 'plugin' => 'something'), false, 'f', 'g', true) + ); + } + + public function testAppLink() + { + $h = new Url($this->container); + $this->assertEquals( + '<a href="?controller=a&action=b&d=e" class="f" title=\'g\' target="_blank">label</a>', $h->link('label', 'a', 'b', array('d' => 'e'), false, 'f', 'g', true) ); } @@ -36,48 +58,66 @@ class UrlHelperTest extends Base public function testDir() { - $h = new Url($this->container); - $this->assertEquals('', $h->dir()); + $this->container['request'] = new Request($this->container, array( + 'PHP_SELF' => '/kanboard/index.php', + 'REQUEST_METHOD' => 'GET' + ) + ); - $_SERVER['REQUEST_METHOD'] = 'GET'; - $_SERVER['PHP_SELF'] = '/plop/index.php'; $h = new Url($this->container); - $this->assertEquals('/plop/', $h->dir()); + $this->assertEquals('/kanboard/', $h->dir()); + + $this->container['request'] = new Request($this->container, array( + 'PHP_SELF' => '/index.php', + 'REQUEST_METHOD' => 'GET' + ) + ); - $_SERVER['REQUEST_METHOD'] = 'GET'; - $_SERVER['PHP_SELF'] = ''; $h = new Url($this->container); $this->assertEquals('/', $h->dir()); } public function testServer() { - $h = new Url($this->container); + $this->container['request'] = new Request($this->container, array( + 'PHP_SELF' => '/index.php', + 'REQUEST_METHOD' => 'GET', + 'SERVER_NAME' => 'localhost', + 'SERVER_PORT' => 80, + ) + ); + $h = new Url($this->container); $this->assertEquals('http://localhost/', $h->server()); - $_SERVER['PHP_SELF'] = '/'; - $_SERVER['SERVER_NAME'] = 'kb'; - $_SERVER['SERVER_PORT'] = 1234; + $this->container['request'] = new Request($this->container, array( + 'PHP_SELF' => '/index.php', + 'REQUEST_METHOD' => 'GET', + 'SERVER_NAME' => 'kb', + 'SERVER_PORT' => 1234, + ) + ); + $h = new Url($this->container); $this->assertEquals('http://kb:1234/', $h->server()); } public function testBase() { - $h = new Url($this->container); - - $this->assertEquals('http://localhost/', $h->base()); - - $_SERVER['PHP_SELF'] = '/'; - $_SERVER['SERVER_NAME'] = 'kb'; - $_SERVER['SERVER_PORT'] = 1234; + $this->container['request'] = new Request($this->container, array( + 'PHP_SELF' => '/index.php', + 'REQUEST_METHOD' => 'GET', + 'SERVER_NAME' => 'kb', + 'SERVER_PORT' => 1234, + ) + ); $h = new Url($this->container); $this->assertEquals('http://kb:1234/', $h->base()); $c = new Config($this->container); $c->save(array('application_url' => 'https://mykanboard/')); + $this->container['memoryCache']->flush(); $h = new Url($this->container); $this->assertEquals('https://mykanboard/', $c->get('application_url')); diff --git a/tests/units/Helper/UserHelperTest.php b/tests/units/Helper/UserHelperTest.php index 4cc9fa65..f1099faa 100644 --- a/tests/units/Helper/UserHelperTest.php +++ b/tests/units/Helper/UserHelperTest.php @@ -4,179 +4,227 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Helper\User; use Kanboard\Model\Project; -use Kanboard\Model\ProjectPermission; +use Kanboard\Model\ProjectUserRole; use Kanboard\Model\User as UserModel; -use Kanboard\Core\Session; +use Kanboard\Core\Security\Role; class UserHelperTest extends Base { public function testInitials() { - $h = new User($this->container); + $helper = new User($this->container); - $this->assertEquals('CN', $h->getInitials('chuck norris')); - $this->assertEquals('A', $h->getInitials('admin')); + $this->assertEquals('CN', $helper->getInitials('chuck norris')); + $this->assertEquals('A', $helper->getInitials('admin')); } - public function testIsProjectAdministrationAllowedForProjectAdmin() + public function testGetRoleName() { - $h = new User($this->container); - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $u = new UserModel($this->container); - $session = new Session; - - // We create our user - $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest'))); - - // We create a project and set our user as project manager - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertTrue($pp->addMember(1, 2)); - $this->assertTrue($pp->isMember(1, 2)); - $this->assertFalse($pp->isManager(1, 2)); - - // We fake a session for him - $session['user'] = array( + $helper = new User($this->container); + $this->assertEquals('Administrator', $helper->getRoleName(Role::APP_ADMIN)); + $this->assertEquals('Manager', $helper->getRoleName(Role::APP_MANAGER)); + $this->assertEquals('Project Viewer', $helper->getRoleName(Role::PROJECT_VIEWER)); + } + + public function testHasAccessForAdmins() + { + $helper = new User($this->container); + + $this->container['sessionStorage']->user = array( + 'id' => 2, + 'role' => Role::APP_ADMIN, + ); + + $this->assertTrue($helper->hasAccess('user', 'create')); + $this->assertTrue($helper->hasAccess('ProjectCreation', 'create')); + $this->assertTrue($helper->hasAccess('ProjectCreation', 'createPrivate')); + } + + public function testHasAccessForManagers() + { + $helper = new User($this->container); + + $this->container['sessionStorage']->user = array( + 'id' => 2, + 'role' => Role::APP_MANAGER, + ); + + $this->assertFalse($helper->hasAccess('user', 'create')); + $this->assertTrue($helper->hasAccess('ProjectCreation', 'create')); + $this->assertTrue($helper->hasAccess('ProjectCreation', 'createPrivate')); + } + + public function testHasAccessForUsers() + { + $helper = new User($this->container); + + $this->container['sessionStorage']->user = array( + 'id' => 2, + 'role' => Role::APP_USER, + ); + + $this->assertFalse($helper->hasAccess('user', 'create')); + $this->assertFalse($helper->hasAccess('ProjectCreation', 'create')); + $this->assertTrue($helper->hasAccess('ProjectCreation', 'createPrivate')); + } + + public function testHasProjectAccessForAdmins() + { + $helper = new User($this->container); + $project = new Project($this->container); + + $this->container['sessionStorage']->user = array( + 'id' => 2, + 'role' => Role::APP_ADMIN, + ); + + $this->assertEquals(1, $project->create(array('name' => 'My project'))); + + $this->assertTrue($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); + $this->assertTrue($helper->hasProjectAccess('board', 'show', 1)); + } + + public function testHasProjectAccessForManagers() + { + $helper = new User($this->container); + $project = new Project($this->container); + + $this->container['sessionStorage']->user = array( 'id' => 2, - 'is_admin' => false, - 'is_project_admin' => true, + 'role' => Role::APP_MANAGER, ); - $this->assertTrue($h->isProjectAdministrationAllowed(1)); + $this->assertEquals(1, $project->create(array('name' => 'My project'))); + + $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); + $this->assertFalse($helper->hasProjectAccess('board', 'show', 1)); } - public function testIsProjectAdministrationAllowedForProjectMember() + public function testHasProjectAccessForUsers() { - $h = new User($this->container); - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $u = new UserModel($this->container); - $session = new Session; - - // We create our user - $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest'))); - - // We create a project and set our user as project member - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertTrue($pp->addMember(1, 2)); - $this->assertTrue($pp->isMember(1, 2)); - $this->assertFalse($pp->isManager(1, 2)); - - // We fake a session for him - $session['user'] = array( + $helper = new User($this->container); + $project = new Project($this->container); + + $this->container['sessionStorage']->user = array( 'id' => 2, - 'is_admin' => false, - 'is_project_admin' => false, + 'role' => Role::APP_USER, ); - $this->assertFalse($h->isProjectAdministrationAllowed(1)); + $this->assertEquals(1, $project->create(array('name' => 'My project'))); + + $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); + $this->assertFalse($helper->hasProjectAccess('board', 'show', 1)); } - public function testIsProjectAdministrationAllowedForProjectManager() + public function testHasProjectAccessForAppManagerAndProjectManagers() { - $h = new User($this->container); - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $u = new UserModel($this->container); - $session = new Session; - - // We create our user - $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest'))); - - // We create a project and set our user as project member - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertTrue($pp->addManager(1, 2)); - $this->assertTrue($pp->isMember(1, 2)); - $this->assertTrue($pp->isManager(1, 2)); - - // We fake a session for him - $session['user'] = array( + $helper = new User($this->container); + $user = new UserModel($this->container); + $project = new Project($this->container); + $projectUserRole = new ProjectUserRole($this->container); + + $this->container['sessionStorage']->user = array( 'id' => 2, - 'is_admin' => false, - 'is_project_admin' => false, + 'role' => Role::APP_MANAGER, ); - $this->assertFalse($h->isProjectAdministrationAllowed(1)); + $this->assertEquals(1, $project->create(array('name' => 'My project'))); + $this->assertEquals(2, $project->create(array('name' => 'My project'))); + $this->assertEquals(2, $user->create(array('username' => 'user'))); + $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_MANAGER)); + + $this->assertTrue($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); + $this->assertTrue($helper->hasProjectAccess('board', 'show', 1)); + $this->assertTrue($helper->hasProjectAccess('task', 'show', 1)); + $this->assertTrue($helper->hasProjectAccess('taskcreation', 'save', 1)); + + $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 2)); + $this->assertFalse($helper->hasProjectAccess('board', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('task', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('taskcreation', 'save', 2)); } - public function testIsProjectManagementAllowedForProjectAdmin() + public function testHasProjectAccessForProjectManagers() { - $h = new User($this->container); - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $u = new UserModel($this->container); - $session = new Session; - - // We create our user - $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest'))); - - // We create a project and set our user as project manager - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertTrue($pp->addMember(1, 2)); - $this->assertTrue($pp->isMember(1, 2)); - $this->assertFalse($pp->isManager(1, 2)); - - // We fake a session for him - $session['user'] = array( + $helper = new User($this->container); + $user = new UserModel($this->container); + $project = new Project($this->container); + $projectUserRole = new ProjectUserRole($this->container); + + $this->container['sessionStorage']->user = array( 'id' => 2, - 'is_admin' => false, - 'is_project_admin' => true, + 'role' => Role::APP_USER, ); - $this->assertTrue($h->isProjectManagementAllowed(1)); + $this->assertEquals(1, $project->create(array('name' => 'My project'))); + $this->assertEquals(2, $project->create(array('name' => 'My project'))); + $this->assertEquals(2, $user->create(array('username' => 'user'))); + $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_MANAGER)); + + $this->assertTrue($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); + $this->assertTrue($helper->hasProjectAccess('board', 'show', 1)); + $this->assertTrue($helper->hasProjectAccess('task', 'show', 1)); + $this->assertTrue($helper->hasProjectAccess('taskcreation', 'save', 1)); + + $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 2)); + $this->assertFalse($helper->hasProjectAccess('board', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('task', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('taskcreation', 'save', 2)); } - public function testIsProjectManagementAllowedForProjectMember() + public function testHasProjectAccessForProjectMembers() { - $h = new User($this->container); - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $u = new UserModel($this->container); - $session = new Session; - - // We create our user - $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest'))); - - // We create a project and set our user as project member - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertTrue($pp->addMember(1, 2)); - $this->assertTrue($pp->isMember(1, 2)); - $this->assertFalse($pp->isManager(1, 2)); - - // We fake a session for him - $session['user'] = array( + $helper = new User($this->container); + $user = new UserModel($this->container); + $project = new Project($this->container); + $projectUserRole = new ProjectUserRole($this->container); + + $this->container['sessionStorage']->user = array( 'id' => 2, - 'is_admin' => false, - 'is_project_admin' => false, + 'role' => Role::APP_USER, ); - $this->assertFalse($h->isProjectManagementAllowed(1)); + $this->assertEquals(1, $project->create(array('name' => 'My project'))); + $this->assertEquals(2, $project->create(array('name' => 'My project'))); + $this->assertEquals(2, $user->create(array('username' => 'user'))); + $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_MEMBER)); + + $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); + $this->assertTrue($helper->hasProjectAccess('board', 'show', 1)); + $this->assertTrue($helper->hasProjectAccess('task', 'show', 1)); + $this->assertTrue($helper->hasProjectAccess('taskcreation', 'save', 1)); + + $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 2)); + $this->assertFalse($helper->hasProjectAccess('board', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('task', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('taskcreation', 'save', 2)); } - public function testIsProjectManagementAllowedForProjectManager() + public function testHasProjectAccessForProjectViewers() { - $h = new User($this->container); - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $u = new UserModel($this->container); - $session = new Session; - - // We create our user - $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest'))); - - // We create a project and set our user as project member - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertTrue($pp->addManager(1, 2)); - $this->assertTrue($pp->isMember(1, 2)); - $this->assertTrue($pp->isManager(1, 2)); - - // We fake a session for him - $session['user'] = array( + $helper = new User($this->container); + $user = new UserModel($this->container); + $project = new Project($this->container); + $projectUserRole = new ProjectUserRole($this->container); + + $this->container['sessionStorage']->user = array( 'id' => 2, - 'is_admin' => false, - 'is_project_admin' => false, + 'role' => Role::APP_USER, ); - $this->assertTrue($h->isProjectManagementAllowed(1)); + $this->assertEquals(1, $project->create(array('name' => 'My project'))); + $this->assertEquals(2, $project->create(array('name' => 'My project'))); + $this->assertEquals(2, $user->create(array('username' => 'user'))); + $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_VIEWER)); + + $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); + $this->assertTrue($helper->hasProjectAccess('board', 'show', 1)); + $this->assertTrue($helper->hasProjectAccess('task', 'show', 1)); + $this->assertFalse($helper->hasProjectAccess('taskcreation', 'save', 1)); + + $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 2)); + $this->assertFalse($helper->hasProjectAccess('board', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('task', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('taskcreation', 'save', 2)); } } |