diff options
Diffstat (limited to 'tests/units/Model')
-rw-r--r-- | tests/units/Model/ProjectDuplicationTest.php | 383 |
1 files changed, 258 insertions, 125 deletions
diff --git a/tests/units/Model/ProjectDuplicationTest.php b/tests/units/Model/ProjectDuplicationTest.php index db5da525..ee5b4ce4 100644 --- a/tests/units/Model/ProjectDuplicationTest.php +++ b/tests/units/Model/ProjectDuplicationTest.php @@ -6,8 +6,11 @@ use Kanboard\Model\Action; use Kanboard\Model\Project; use Kanboard\Model\Category; use Kanboard\Model\ProjectUserRole; +use Kanboard\Model\ProjectGroupRole; use Kanboard\Model\ProjectDuplication; use Kanboard\Model\User; +use Kanboard\Model\Group; +use Kanboard\Model\GroupMember; use Kanboard\Model\Swimlane; use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; @@ -16,7 +19,14 @@ use Kanboard\Core\Security\Role; class ProjectDuplicationTest extends Base { - public function testProjectName() + public function testGetSelections() + { + $projectDuplicationModel = new ProjectDuplication($this->container); + $this->assertCount(5, $projectDuplicationModel->getOptionalSelection()); + $this->assertCount(6, $projectDuplicationModel->getPossibleSelection()); + } + + public function testGetClonedProjectName() { $pd = new ProjectDuplication($this->container); @@ -29,54 +39,142 @@ class ProjectDuplicationTest extends Base $this->assertEquals(str_repeat('a', 42).' (Clone)', $pd->getClonedProjectName(str_repeat('a', 60))); } - public function testCopyProjectWithLongName() + public function testClonePublicProject() { $p = new Project($this->container); $pd = new ProjectDuplication($this->container); - $this->assertEquals(1, $p->create(array('name' => str_repeat('a', 50)))); + $this->assertEquals(1, $p->create(array('name' => 'Public'))); $this->assertEquals(2, $pd->duplicate(1)); $project = $p->getById(2); $this->assertNotEmpty($project); - $this->assertEquals(str_repeat('a', 42).' (Clone)', $project['name']); + $this->assertEquals('Public (Clone)', $project['name']); + $this->assertEquals(1, $project['is_active']); + $this->assertEquals(0, $project['is_private']); + $this->assertEquals(0, $project['is_public']); + $this->assertEquals(0, $project['owner_id']); + $this->assertEmpty($project['token']); } - public function testClonePublicProject() + public function testClonePrivateProject() { $p = new Project($this->container); $pd = new ProjectDuplication($this->container); + $pp = new ProjectUserRole($this->container); - $this->assertEquals(1, $p->create(array('name' => 'Public'))); + $this->assertEquals(1, $p->create(array('name' => 'Private', 'is_private' => 1), 1, true)); $this->assertEquals(2, $pd->duplicate(1)); $project = $p->getById(2); $this->assertNotEmpty($project); - $this->assertEquals('Public (Clone)', $project['name']); - $this->assertEquals(0, $project['is_private']); + $this->assertEquals('Private (Clone)', $project['name']); + $this->assertEquals(1, $project['is_active']); + $this->assertEquals(1, $project['is_private']); $this->assertEquals(0, $project['is_public']); + $this->assertEquals(0, $project['owner_id']); $this->assertEmpty($project['token']); + + $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 1)); } - public function testClonePrivateProject() + public function testCloneSharedProject() { $p = new Project($this->container); $pd = new ProjectDuplication($this->container); - $this->assertEquals(1, $p->create(array('name' => 'Private', 'is_private' => 1), 1, true)); + $this->assertEquals(1, $p->create(array('name' => 'Shared'))); + $this->assertTrue($p->update(array('id' => 1, 'is_public' => 1, 'token' => 'test'))); + + $project = $p->getById(1); + $this->assertEquals('test', $project['token']); + $this->assertEquals(1, $project['is_public']); + $this->assertEquals(2, $pd->duplicate(1)); $project = $p->getById(2); $this->assertNotEmpty($project); - $this->assertEquals('Private (Clone)', $project['name']); - $this->assertEquals(1, $project['is_private']); + $this->assertEquals('Shared (Clone)', $project['name']); + $this->assertEquals('', $project['token']); $this->assertEquals(0, $project['is_public']); - $this->assertEmpty($project['token']); + } - $pp = new ProjectUserRole($this->container); + public function testCloneInactiveProject() + { + $p = new Project($this->container); + $pd = new ProjectDuplication($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'Inactive'))); + $this->assertTrue($p->update(array('id' => 1, 'is_active' => 0))); + + $project = $p->getById(1); + $this->assertEquals(0, $project['is_active']); + + $this->assertEquals(2, $pd->duplicate(1)); + + $project = $p->getById(2); + $this->assertNotEmpty($project); + $this->assertEquals('Inactive (Clone)', $project['name']); + $this->assertEquals(1, $project['is_active']); + } + + public function testCloneProjectWithOwner() + { + $p = new Project($this->container); + $pd = new ProjectDuplication($this->container); + $projectUserRoleModel = new ProjectUserRole($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'Owner'))); + + $project = $p->getById(1); + $this->assertEquals(0, $project['owner_id']); + + $this->assertEquals(2, $pd->duplicate(1, array('projectPermission'), 1)); - $this->assertEquals(array(1 => 'admin'), $pp->getAssignableUsers(1)); - $this->assertEquals(array(1 => 'admin'), $pp->getAssignableUsers(2)); + $project = $p->getById(2); + $this->assertNotEmpty($project); + $this->assertEquals('Owner (Clone)', $project['name']); + $this->assertEquals(1, $project['owner_id']); + + $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 1)); + } + + public function testCloneProjectWithDifferentName() + { + $p = new Project($this->container); + $pd = new ProjectDuplication($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'Owner'))); + + $project = $p->getById(1); + $this->assertEquals(0, $project['owner_id']); + + $this->assertEquals(2, $pd->duplicate(1, array('projectPermission'), 1, 'Foobar')); + + $project = $p->getById(2); + $this->assertNotEmpty($project); + $this->assertEquals('Foobar', $project['name']); + $this->assertEquals(1, $project['owner_id']); + } + + public function testCloneProjectAndForceItToBePrivate() + { + $p = new Project($this->container); + $pd = new ProjectDuplication($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'Owner'))); + + $project = $p->getById(1); + $this->assertEquals(0, $project['owner_id']); + $this->assertEquals(0, $project['is_private']); + + $this->assertEquals(2, $pd->duplicate(1, array('projectPermission'), 1, 'Foobar', true)); + + $project = $p->getById(2); + $this->assertNotEmpty($project); + $this->assertEquals('Foobar', $project['name']); + $this->assertEquals(1, $project['owner_id']); + $this->assertEquals(1, $project['is_private']); } public function testCloneProjectWithCategories() @@ -98,16 +196,9 @@ class ProjectDuplicationTest extends Base $this->assertEquals('P1 (Clone)', $project['name']); $categories = $c->getAll(2); - $this->assertNotempty($categories); - $this->assertEquals(3, count($categories)); - - $this->assertEquals(4, $categories[0]['id']); + $this->assertCount(3, $categories); $this->assertEquals('C1', $categories[0]['name']); - - $this->assertEquals(5, $categories[1]['id']); $this->assertEquals('C2', $categories[1]['name']); - - $this->assertEquals(6, $categories[2]['id']); $this->assertEquals('C3', $categories[2]['name']); } @@ -119,28 +210,115 @@ class ProjectDuplicationTest extends Base $u = new User($this->container); $pd = new ProjectDuplication($this->container); - $this->assertEquals(2, $u->create(array('username' => 'unittest1', 'password' => 'unittest'))); - $this->assertEquals(3, $u->create(array('username' => 'unittest2', 'password' => 'unittest'))); - $this->assertEquals(4, $u->create(array('username' => 'unittest3', 'password' => 'unittest'))); + $this->assertEquals(2, $u->create(array('username' => 'user1'))); + $this->assertEquals(3, $u->create(array('username' => 'user2'))); + $this->assertEquals(4, $u->create(array('username' => 'user3'))); $this->assertEquals(1, $p->create(array('name' => 'P1'))); - $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER)); + + $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MANAGER)); $this->assertTrue($pp->addUser(1, 3, Role::PROJECT_MEMBER)); - $this->assertTrue($pp->addUser(1, 4, Role::PROJECT_MANAGER)); - $this->assertEquals(Role::PROJECT_MEMBER, $pp->getUserRole(1, 2)); - $this->assertEquals(Role::PROJECT_MEMBER, $pp->getUserRole(1, 3)); - $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(1, 4)); + $this->assertTrue($pp->addUser(1, 4, Role::PROJECT_VIEWER)); $this->assertEquals(2, $pd->duplicate(1)); + $this->assertCount(3, $pp->getUsers(2)); + $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 2)); + $this->assertEquals(Role::PROJECT_MEMBER, $pp->getUserRole(2, 3)); + $this->assertEquals(Role::PROJECT_VIEWER, $pp->getUserRole(2, 4)); + } + + public function testCloneProjectWithUsersAndOverrideOwner() + { + $p = new Project($this->container); + $c = new Category($this->container); + $pp = new ProjectUserRole($this->container); + $u = new User($this->container); + $pd = new ProjectDuplication($this->container); + + $this->assertEquals(2, $u->create(array('username' => 'user1'))); + $this->assertEquals(1, $p->create(array('name' => 'P1'), 2)); + + $project = $p->getById(1); + $this->assertEquals(2, $project['owner_id']); + + $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MANAGER)); + $this->assertTrue($pp->addUser(1, 1, Role::PROJECT_MEMBER)); + + $this->assertEquals(2, $pd->duplicate(1, array('projectPermission'), 1)); + + $this->assertCount(2, $pp->getUsers(2)); + $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 2)); + $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 1)); + $project = $p->getById(2); - $this->assertNotEmpty($project); - $this->assertEquals('P1 (Clone)', $project['name']); + $this->assertEquals(1, $project['owner_id']); + } - $this->assertEquals(3, count($pp->getUsers(2))); - $this->assertEquals(Role::PROJECT_MEMBER, $pp->getUserRole(2, 2)); - $this->assertEquals(Role::PROJECT_MEMBER, $pp->getUserRole(2, 3)); - $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 4)); + public function testCloneTeamProjectToPrivatProject() + { + $p = new Project($this->container); + $c = new Category($this->container); + $pp = new ProjectUserRole($this->container); + $u = new User($this->container); + $pd = new ProjectDuplication($this->container); + + $this->assertEquals(2, $u->create(array('username' => 'user1'))); + $this->assertEquals(3, $u->create(array('username' => 'user2'))); + $this->assertEquals(1, $p->create(array('name' => 'P1'), 2)); + + $project = $p->getById(1); + $this->assertEquals(2, $project['owner_id']); + $this->assertEquals(0, $project['is_private']); + + $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MANAGER)); + $this->assertTrue($pp->addUser(1, 1, Role::PROJECT_MEMBER)); + + $this->assertEquals(2, $pd->duplicate(1, array('projectPermission'), 3, 'My private project', true)); + + $this->assertCount(1, $pp->getUsers(2)); + $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 3)); + + $project = $p->getById(2); + $this->assertEquals(3, $project['owner_id']); + $this->assertEquals(1, $project['is_private']); + } + + public function testCloneProjectWithGroups() + { + $p = new Project($this->container); + $c = new Category($this->container); + $pd = new ProjectDuplication($this->container); + $userModel = new User($this->container); + $groupModel = new Group($this->container); + $groupMemberModel = new GroupMember($this->container); + $projectGroupRoleModel = new ProjectGroupRole($this->container); + $projectUserRoleModel = new ProjectUserRole($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'P1'))); + + $this->assertEquals(1, $groupModel->create('G1')); + $this->assertEquals(2, $groupModel->create('G2')); + $this->assertEquals(3, $groupModel->create('G3')); + + $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->assertTrue($groupMemberModel->addUser(1, 2)); + $this->assertTrue($groupMemberModel->addUser(2, 3)); + $this->assertTrue($groupMemberModel->addUser(3, 4)); + + $this->assertTrue($projectGroupRoleModel->addGroup(1, 1, Role::PROJECT_MANAGER)); + $this->assertTrue($projectGroupRoleModel->addGroup(1, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($projectGroupRoleModel->addGroup(1, 3, Role::PROJECT_VIEWER)); + + $this->assertEquals(2, $pd->duplicate(1)); + + $this->assertCount(3, $projectGroupRoleModel->getGroups(2)); + $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 2)); + $this->assertEquals(Role::PROJECT_MEMBER, $projectUserRoleModel->getUserRole(2, 3)); + $this->assertEquals(Role::PROJECT_VIEWER, $projectUserRoleModel->getUserRole(2, 4)); } public function testCloneProjectWithActionTaskAssignCurrentUser() @@ -199,7 +377,7 @@ class ProjectDuplicationTest extends Base $this->assertEquals(5, $actions[0]['params']['category_id']); } - public function testCloneProjectWithSwimlanesAndTasks() + public function testCloneProjectWithSwimlanes() { $p = new Project($this->container); $pd = new ProjectDuplication($this->container); @@ -207,31 +385,22 @@ class ProjectDuplicationTest extends Base $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); - $this->assertEquals(1, $p->create(array('name' => 'P1'))); + $this->assertEquals(1, $p->create(array('name' => 'P1', 'default_swimlane' => 'New Default'))); // create initial swimlanes $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'S1'))); $this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'S2'))); $this->assertEquals(3, $s->create(array('project_id' => 1, 'name' => 'S3'))); - $default_swimlane1 = $s->getDefault(1); - $default_swimlane1['default_swimlane'] = 'New Default'; - - $this->assertTrue($s->updateDefault($default_swimlane1)); + // create initial tasks + $this->assertEquals(1, $tc->create(array('title' => 'T0', 'project_id' => 1, 'swimlane_id' => 0))); + $this->assertEquals(2, $tc->create(array('title' => 'T1', 'project_id' => 1, 'swimlane_id' => 1))); + $this->assertEquals(3, $tc->create(array('title' => 'T2', 'project_id' => 1, 'swimlane_id' => 2))); + $this->assertEquals(4, $tc->create(array('title' => 'T3', 'project_id' => 1, 'swimlane_id' => 3))); - //create initial tasks - $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); - $this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1))); - $this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); - - $this->assertNotFalse($pd->duplicate(1, array('category', 'action', 'swimlane', 'task'))); - $project = $p->getByName('P1 (Clone)'); - $this->assertNotFalse($project); - $project_id = $project['id']; - - // Check if Swimlanes have been duplicated - $swimlanes = $s->getAll($project_id); + $this->assertEquals(2, $pd->duplicate(1, array('category', 'swimlane'))); + $swimlanes = $s->getAll(2); $this->assertCount(3, $swimlanes); $this->assertEquals(4, $swimlanes[0]['id']); $this->assertEquals('S1', $swimlanes[0]['name']); @@ -239,29 +408,15 @@ class ProjectDuplicationTest extends Base $this->assertEquals('S2', $swimlanes[1]['name']); $this->assertEquals(6, $swimlanes[2]['id']); $this->assertEquals('S3', $swimlanes[2]['name']); - $new_default = $s->getDefault($project_id); - $this->assertEquals('New Default', $new_default['default_swimlane']); - - // Check if Tasks have been duplicated - $tasks = $tf->getAll($project_id); + $swimlane = $s->getDefault(2); + $this->assertEquals('New Default', $swimlane['default_swimlane']); - $this->assertCount(3, $tasks); - // $this->assertEquals(4, $tasks[0]['id']); - $this->assertEquals('T1', $tasks[0]['title']); - // $this->assertEquals(5, $tasks[1]['id']); - $this->assertEquals('T2', $tasks[1]['title']); - // $this->assertEquals(6, $tasks[2]['id']); - $this->assertEquals('T3', $tasks[2]['title']); - - $p->remove($project_id); - - $this->assertFalse($p->exists($project_id)); - $this->assertCount(0, $s->getAll($project_id)); - $this->assertCount(0, $tf->getAll($project_id)); + // Check if tasks are NOT been duplicated + $this->assertCount(0, $tf->getAll(2)); } - public function testCloneProjectWithSwimlanes() + public function testCloneProjectWithTasks() { $p = new Project($this->container); $pd = new ProjectDuplication($this->container); @@ -271,43 +426,22 @@ class ProjectDuplicationTest extends Base $this->assertEquals(1, $p->create(array('name' => 'P1'))); - // create initial swimlanes - $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'S1'))); - $this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'S2'))); - $this->assertEquals(3, $s->create(array('project_id' => 1, 'name' => 'S3'))); + // create initial tasks + $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1))); + $this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2))); + $this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3))); - $default_swimlane1 = $s->getDefault(1); - $default_swimlane1['default_swimlane'] = 'New Default'; - - $this->assertTrue($s->updateDefault($default_swimlane1)); - - //create initial tasks - $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); - $this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1))); - $this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); - - $this->assertNotFalse($pd->duplicate(1, array('category', 'action', 'swimlane'))); - $project = $p->getByName('P1 (Clone)'); - $this->assertNotFalse($project); - $project_id = $project['id']; - - $swimlanes = $s->getAll($project_id); - - $this->assertCount(3, $swimlanes); - $this->assertEquals(4, $swimlanes[0]['id']); - $this->assertEquals('S1', $swimlanes[0]['name']); - $this->assertEquals(5, $swimlanes[1]['id']); - $this->assertEquals('S2', $swimlanes[1]['name']); - $this->assertEquals(6, $swimlanes[2]['id']); - $this->assertEquals('S3', $swimlanes[2]['name']); - $new_default = $s->getDefault($project_id); - $this->assertEquals('New Default', $new_default['default_swimlane']); + $this->assertEquals(2, $pd->duplicate(1, array('category', 'action', 'task'))); - // Check if Tasks have NOT been duplicated - $this->assertCount(0, $tf->getAll($project_id)); + // Check if Tasks have been duplicated + $tasks = $tf->getAll(2); + $this->assertCount(3, $tasks); + $this->assertEquals('T1', $tasks[0]['title']); + $this->assertEquals('T2', $tasks[1]['title']); + $this->assertEquals('T3', $tasks[2]['title']); } - public function testCloneProjectWithTasks() + public function testCloneProjectWithSwimlanesAndTasks() { $p = new Project($this->container); $pd = new ProjectDuplication($this->container); @@ -315,40 +449,39 @@ class ProjectDuplicationTest extends Base $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); - $this->assertEquals(1, $p->create(array('name' => 'P1'))); + $this->assertEquals(1, $p->create(array('name' => 'P1', 'default_swimlane' => 'New Default'))); // create initial swimlanes $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'S1'))); $this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'S2'))); $this->assertEquals(3, $s->create(array('project_id' => 1, 'name' => 'S3'))); - $default_swimlane1 = $s->getDefault(1); - $default_swimlane1['default_swimlane'] = 'New Default'; - - $this->assertTrue($s->updateDefault($default_swimlane1)); - - //create initial tasks + // create initial tasks $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); $this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1))); $this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); - $this->assertNotFalse($pd->duplicate(1, array('category', 'action', 'task'))); - $project = $p->getByName('P1 (Clone)'); - $this->assertNotFalse($project); - $project_id = $project['id']; + $this->assertEquals(2, $pd->duplicate(1, array('projectPermission', 'swimlane', 'task'))); + + // Check if Swimlanes have been duplicated + $swimlanes = $s->getAll(2); + $this->assertCount(3, $swimlanes); + $this->assertEquals(4, $swimlanes[0]['id']); + $this->assertEquals('S1', $swimlanes[0]['name']); + $this->assertEquals(5, $swimlanes[1]['id']); + $this->assertEquals('S2', $swimlanes[1]['name']); + $this->assertEquals(6, $swimlanes[2]['id']); + $this->assertEquals('S3', $swimlanes[2]['name']); - // Check if Swimlanes have NOT been duplicated - $this->assertCount(0, $s->getAll($project_id)); + $swimlane = $s->getDefault(2); + $this->assertEquals('New Default', $swimlane['default_swimlane']); // Check if Tasks have been duplicated - $tasks = $tf->getAll($project_id); + $tasks = $tf->getAll(2); $this->assertCount(3, $tasks); - //$this->assertEquals(4, $tasks[0]['id']); $this->assertEquals('T1', $tasks[0]['title']); - //$this->assertEquals(5, $tasks[1]['id']); $this->assertEquals('T2', $tasks[1]['title']); - //$this->assertEquals(6, $tasks[2]['id']); $this->assertEquals('T3', $tasks[2]['title']); } } |