diff options
Diffstat (limited to 'tests/units')
-rw-r--r-- | tests/units/Model/ProjectPermissionTest.php | 66 | ||||
-rw-r--r-- | tests/units/Model/TaskPositionTest.php | 4 | ||||
-rw-r--r-- | tests/units/Model/UserMentionTest.php | 114 |
3 files changed, 181 insertions, 3 deletions
diff --git a/tests/units/Model/ProjectPermissionTest.php b/tests/units/Model/ProjectPermissionTest.php index 77419bec..035a1246 100644 --- a/tests/units/Model/ProjectPermissionTest.php +++ b/tests/units/Model/ProjectPermissionTest.php @@ -13,6 +13,33 @@ use Kanboard\Core\Security\Role; class ProjectPermissionTest extends Base { + public function testFindByUsernames() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupMemberModel = new GroupMember($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + $userRoleModel = new ProjectUserRole($this->container); + $projectPermissionModel = new ProjectPermission($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user3'))); + + $this->assertEquals(1, $groupModel->create('Group A')); + $this->assertTrue($groupMemberModel->addUser(1, 2)); + + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_MANAGER)); + + $this->assertEquals(array('user1', 'user2'), $projectPermissionModel->findUsernames(1, 'us')); + $this->assertEmpty($projectPermissionModel->findUsernames(1, 'a')); + $this->assertEmpty($projectPermissionModel->findUsernames(2, 'user')); + } + public function testGetQueryByRole() { $userModel = new User($this->container); @@ -128,6 +155,43 @@ class ProjectPermissionTest extends Base $this->assertFalse($projectPermission->isUserAllowed(2, 5)); } + public function testIsAssignable() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + $groupMemberModel = new GroupMember($this->container); + $userRoleModel = new ProjectUserRole($this->container); + $projectPermission = new ProjectPermission($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'user 1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user 3'))); + $this->assertEquals(5, $userModel->create(array('username' => 'user 4'))); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); + + $this->assertEquals(1, $groupModel->create('Group A')); + + $this->assertTrue($groupMemberModel->addUser(1, 2)); + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER)); + + $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(1, 4, Role::PROJECT_MANAGER)); + + $this->assertFalse($projectPermission->isAssignable(1, 2)); + $this->assertTrue($projectPermission->isAssignable(1, 3)); + $this->assertTrue($projectPermission->isAssignable(1, 4)); + $this->assertFalse($projectPermission->isAssignable(1, 5)); + + $this->assertFalse($projectPermission->isAssignable(2, 2)); + $this->assertFalse($projectPermission->isAssignable(2, 3)); + $this->assertFalse($projectPermission->isAssignable(2, 4)); + $this->assertFalse($projectPermission->isAssignable(2, 5)); + } + public function testIsMember() { $userModel = new User($this->container); @@ -154,7 +218,7 @@ class ProjectPermissionTest extends Base $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_MEMBER)); $this->assertTrue($userRoleModel->addUser(1, 4, Role::PROJECT_MANAGER)); - $this->assertFalse($projectPermission->isMember(1, 2)); + $this->assertTrue($projectPermission->isMember(1, 2)); $this->assertTrue($projectPermission->isMember(1, 3)); $this->assertTrue($projectPermission->isMember(1, 4)); $this->assertFalse($projectPermission->isMember(1, 5)); diff --git a/tests/units/Model/TaskPositionTest.php b/tests/units/Model/TaskPositionTest.php index 42612f44..5f045768 100644 --- a/tests/units/Model/TaskPositionTest.php +++ b/tests/units/Model/TaskPositionTest.php @@ -106,7 +106,7 @@ class TaskPositionTest extends Base $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1))); $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1))); - // We move the task 2 to the column 3 + // We move the task 1 to the column 3 $this->assertTrue($tp->movePosition(1, 1, 3, 1)); // Check tasks position @@ -235,7 +235,7 @@ class TaskPositionTest extends Base $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1))); $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1))); - // Move the last task to the bottom + // Move the first task to the bottom $this->assertTrue($tp->movePosition(1, 1, 1, 4)); // Check tasks position diff --git a/tests/units/Model/UserMentionTest.php b/tests/units/Model/UserMentionTest.php new file mode 100644 index 00000000..d50c9285 --- /dev/null +++ b/tests/units/Model/UserMentionTest.php @@ -0,0 +1,114 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Core\Security\Role; +use Kanboard\Event\GenericEvent; +use Kanboard\Model\User; +use Kanboard\Model\Task; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\Project; +use Kanboard\Model\ProjectUserRole; +use Kanboard\Model\UserMention; + +class UserMentionTest extends Base +{ + public function testGetMentionedUsersWithNoMentions() + { + $userModel = new User($this->container); + $userMentionModel = new UserMention($this->container); + + $this->assertNotFalse($userModel->create(array('username' => 'user1'))); + $this->assertEmpty($userMentionModel->getMentionedUsers('test')); + } + + public function testGetMentionedUsersWithNotficationDisabled() + { + $userModel = new User($this->container); + $userMentionModel = new UserMention($this->container); + + $this->assertNotFalse($userModel->create(array('username' => 'user1'))); + $this->assertEmpty($userMentionModel->getMentionedUsers('test @user1')); + } + + public function testGetMentionedUsersWithNotficationEnabled() + { + $userModel = new User($this->container); + $userMentionModel = new UserMention($this->container); + + $this->assertNotFalse($userModel->create(array('username' => 'user1'))); + $this->assertNotFalse($userModel->create(array('username' => 'user2', 'name' => 'Foobar', 'notifications_enabled' => 1))); + + $users = $userMentionModel->getMentionedUsers('test @user2'); + $this->assertCount(1, $users); + $this->assertEquals('user2', $users[0]['username']); + $this->assertEquals('Foobar', $users[0]['name']); + $this->assertEquals('', $users[0]['email']); + $this->assertEquals('', $users[0]['language']); + } + + public function testGetMentionedUsersWithNotficationEnabledAndUserLoggedIn() + { + $this->container['sessionStorage']->user = array('id' => 3); + $userModel = new User($this->container); + $userMentionModel = new UserMention($this->container); + + $this->assertNotFalse($userModel->create(array('username' => 'user1'))); + $this->assertNotFalse($userModel->create(array('username' => 'user2', 'name' => 'Foobar', 'notifications_enabled' => 1))); + + $this->assertEmpty($userMentionModel->getMentionedUsers('test @user2')); + } + + public function testFireEventsWithMultipleMentions() + { + $projectUserRoleModel = new ProjectUserRole($this->container); + $projectModel = new Project($this->container); + $userModel = new User($this->container); + $userMentionModel = new UserMention($this->container); + $event = new GenericEvent(array('project_id' => 1)); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User 1', 'notifications_enabled' => 1))); + $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User 2', 'notifications_enabled' => 1))); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + $this->assertTrue($projectUserRoleModel->addUser(1, 3, Role::PROJECT_MEMBER)); + + $this->container['dispatcher']->addListener(Task::EVENT_USER_MENTION, array($this, 'onUserMention')); + + $userMentionModel->fireEvents('test @user1 @user2', Task::EVENT_USER_MENTION, $event); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(Task::EVENT_USER_MENTION.'.UserMentionTest::onUserMention', $called); + } + + public function testFireEventsWithNoProjectId() + { + $projectUserRoleModel = new ProjectUserRole($this->container); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $userModel = new User($this->container); + $userMentionModel = new UserMention($this->container); + $event = new GenericEvent(array('task_id' => 1)); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User 1', 'notifications_enabled' => 1))); + $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User 2', 'notifications_enabled' => 1))); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + $this->assertTrue($projectUserRoleModel->addUser(1, 3, Role::PROJECT_MEMBER)); + + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'Task 1'))); + + $this->container['dispatcher']->addListener(Task::EVENT_USER_MENTION, array($this, 'onUserMention')); + + $userMentionModel->fireEvents('test @user1 @user2', Task::EVENT_USER_MENTION, $event); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(Task::EVENT_USER_MENTION.'.UserMentionTest::onUserMention', $called); + } + + public function onUserMention($event) + { + $this->assertInstanceOf('Kanboard\Event\GenericEvent', $event); + $this->assertEquals(array('id' => '3', 'username' => 'user2', 'name' => 'User 2', 'email' => null, 'language' => null), $event['mention']); + } +} |