diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-07-02 15:20:59 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-07-02 15:20:59 -0400 |
commit | 6d5577fa0bc108fcafa92fc4ac4b9ed621bfe33e (patch) | |
tree | bd7b71d282c66c28b3060ccfb0431428b413a139 /tests/units/Model | |
parent | 3fcc0cb9183f9ff32ce7a3c615258bcf53c385ed (diff) |
Handle project tags duplication
Diffstat (limited to 'tests/units/Model')
-rw-r--r-- | tests/units/Model/ProjectDuplicationModelTest.php | 526 | ||||
-rw-r--r-- | tests/units/Model/ProjectDuplicationTest.php | 482 | ||||
-rw-r--r-- | tests/units/Model/TagDuplicationModelTest.php | 31 |
3 files changed, 557 insertions, 482 deletions
diff --git a/tests/units/Model/ProjectDuplicationModelTest.php b/tests/units/Model/ProjectDuplicationModelTest.php new file mode 100644 index 00000000..de7b0d79 --- /dev/null +++ b/tests/units/Model/ProjectDuplicationModelTest.php @@ -0,0 +1,526 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\ActionModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\CategoryModel; +use Kanboard\Model\ProjectUserRoleModel; +use Kanboard\Model\ProjectGroupRoleModel; +use Kanboard\Model\ProjectDuplicationModel; +use Kanboard\Model\TagModel; +use Kanboard\Model\TaskTagModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\GroupModel; +use Kanboard\Model\GroupMemberModel; +use Kanboard\Model\SwimlaneModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Core\Security\Role; + +class ProjectDuplicationModelTest extends Base +{ + public function testGetSelections() + { + $projectDuplicationModel = new ProjectDuplicationModel($this->container); + $this->assertCount(7, $projectDuplicationModel->getOptionalSelection()); + $this->assertCount(8, $projectDuplicationModel->getPossibleSelection()); + } + + public function testGetClonedProjectName() + { + $projectDuplicationModel = new ProjectDuplicationModel($this->container); + + $this->assertEquals('test (Clone)', $projectDuplicationModel->getClonedProjectName('test')); + + $this->assertEquals(50, strlen($projectDuplicationModel->getClonedProjectName(str_repeat('a', 50)))); + $this->assertEquals(str_repeat('a', 42).' (Clone)', $projectDuplicationModel->getClonedProjectName(str_repeat('a', 50))); + + $this->assertEquals(50, strlen($projectDuplicationModel->getClonedProjectName(str_repeat('a', 60)))); + $this->assertEquals(str_repeat('a', 42).' (Clone)', $projectDuplicationModel->getClonedProjectName(str_repeat('a', 60))); + } + + public function testClonePublicProject() + { + $projectModel = new ProjectModel($this->container); + $projectDuplicationModel = new ProjectDuplicationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Public'))); + $this->assertEquals(2, $projectDuplicationModel->duplicate(1)); + + $project = $projectModel->getById(2); + $this->assertNotEmpty($project); + $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 testClonePrivateProject() + { + $projectModel = new ProjectModel($this->container); + $projectDuplicationModel = new ProjectDuplicationModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Private', 'is_private' => 1), 1, true)); + $this->assertEquals(2, $projectDuplicationModel->duplicate(1)); + + $project = $projectModel->getById(2); + $this->assertNotEmpty($project); + $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, $projectUserRoleModel->getUserRole(2, 1)); + } + + public function testCloneSharedProject() + { + $projectModel = new ProjectModel($this->container); + $projectDuplicationModel = new ProjectDuplicationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Shared'))); + $this->assertTrue($projectModel->update(array('id' => 1, 'is_public' => 1, 'token' => 'test'))); + + $project = $projectModel->getById(1); + $this->assertEquals('test', $project['token']); + $this->assertEquals(1, $project['is_public']); + + $this->assertEquals(2, $projectDuplicationModel->duplicate(1)); + + $project = $projectModel->getById(2); + $this->assertNotEmpty($project); + $this->assertEquals('Shared (Clone)', $project['name']); + $this->assertEquals('', $project['token']); + $this->assertEquals(0, $project['is_public']); + } + + public function testCloneInactiveProject() + { + $projectModel = new ProjectModel($this->container); + $projectDuplicationModel = new ProjectDuplicationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Inactive'))); + $this->assertTrue($projectModel->update(array('id' => 1, 'is_active' => 0))); + + $project = $projectModel->getById(1); + $this->assertEquals(0, $project['is_active']); + + $this->assertEquals(2, $projectDuplicationModel->duplicate(1)); + + $project = $projectModel->getById(2); + $this->assertNotEmpty($project); + $this->assertEquals('Inactive (Clone)', $project['name']); + $this->assertEquals(1, $project['is_active']); + } + + public function testCloneProjectWithOwner() + { + $projectModel = new ProjectModel($this->container); + $projectDuplicationModel = new ProjectDuplicationModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Owner'))); + + $project = $projectModel->getById(1); + $this->assertEquals(0, $project['owner_id']); + + $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel'), 1)); + + $project = $projectModel->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() + { + $projectModel = new ProjectModel($this->container); + $projectDuplicationModel = new ProjectDuplicationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Owner'))); + + $project = $projectModel->getById(1); + $this->assertEquals(0, $project['owner_id']); + + $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel'), 1, 'Foobar')); + + $project = $projectModel->getById(2); + $this->assertNotEmpty($project); + $this->assertEquals('Foobar', $project['name']); + $this->assertEquals(1, $project['owner_id']); + } + + public function testCloneProjectAndForceItToBePrivate() + { + $projectModel = new ProjectModel($this->container); + $projectDuplicationModel = new ProjectDuplicationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Owner'))); + + $project = $projectModel->getById(1); + $this->assertEquals(0, $project['owner_id']); + $this->assertEquals(0, $project['is_private']); + + $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel'), 1, 'Foobar', true)); + + $project = $projectModel->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() + { + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); + $projectDuplicationModel = new ProjectDuplicationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + + $this->assertEquals(1, $categoryModel->create(array('name' => 'C1', 'project_id' => 1))); + $this->assertEquals(2, $categoryModel->create(array('name' => 'C2', 'project_id' => 1))); + $this->assertEquals(3, $categoryModel->create(array('name' => 'C3', 'project_id' => 1))); + + $this->assertEquals(2, $projectDuplicationModel->duplicate(1)); + + $project = $projectModel->getById(2); + $this->assertNotEmpty($project); + $this->assertEquals('P1 (Clone)', $project['name']); + + $categories = $categoryModel->getAll(2); + $this->assertCount(3, $categories); + $this->assertEquals('C1', $categories[0]['name']); + $this->assertEquals('C2', $categories[1]['name']); + $this->assertEquals('C3', $categories[2]['name']); + } + + public function testCloneProjectWithUsers() + { + $projectModel = new ProjectModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $userModel = new UserModel($this->container); + $projectDuplicationModel = new ProjectDuplicationModel($this->container); + + $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, $projectModel->create(array('name' => 'P1'))); + + $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MANAGER)); + $this->assertTrue($projectUserRoleModel->addUser(1, 3, Role::PROJECT_MEMBER)); + $this->assertTrue($projectUserRoleModel->addUser(1, 4, Role::PROJECT_VIEWER)); + + $this->assertEquals(2, $projectDuplicationModel->duplicate(1)); + + $this->assertCount(3, $projectUserRoleModel->getUsers(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 testCloneProjectWithUsersAndOverrideOwner() + { + $projectModel = new ProjectModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $userModel = new UserModel($this->container); + $projectDuplicationModel = new ProjectDuplicationModel($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'), 2)); + + $project = $projectModel->getById(1); + $this->assertEquals(2, $project['owner_id']); + + $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MANAGER)); + $this->assertTrue($projectUserRoleModel->addUser(1, 1, Role::PROJECT_MEMBER)); + + $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel'), 1)); + + $this->assertCount(2, $projectUserRoleModel->getUsers(2)); + $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 2)); + $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 1)); + + $project = $projectModel->getById(2); + $this->assertEquals(1, $project['owner_id']); + } + + public function testCloneTeamProjectToPrivatProject() + { + $projectModel = new ProjectModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $userModel = new UserModel($this->container); + $projectDuplicationModel = new ProjectDuplicationModel($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user2'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'), 2)); + + $project = $projectModel->getById(1); + $this->assertEquals(2, $project['owner_id']); + $this->assertEquals(0, $project['is_private']); + + $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MANAGER)); + $this->assertTrue($projectUserRoleModel->addUser(1, 1, Role::PROJECT_MEMBER)); + + $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel'), 3, 'My private project', true)); + + $this->assertCount(1, $projectUserRoleModel->getUsers(2)); + $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 3)); + + $project = $projectModel->getById(2); + $this->assertEquals(3, $project['owner_id']); + $this->assertEquals(1, $project['is_private']); + } + + public function testCloneProjectWithGroups() + { + $projectModel = new ProjectModel($this->container); + $projectDuplicationModel = new ProjectDuplicationModel($this->container); + $userModel = new UserModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $projectGroupRoleModel = new ProjectGroupRoleModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + + $this->assertEquals(1, $projectModel->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, $projectDuplicationModel->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() + { + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + $projectDuplicationModel = new ProjectDuplicationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, + 'action_name' => 'TaskAssignCurrentUser', + 'params' => array('column_id' => 2), + ))); + + $this->assertEquals(2, $projectDuplicationModel->duplicate(1)); + + $actions = $actionModel->getAllByProject(2); + + $this->assertNotEmpty($actions); + $this->assertEquals('TaskAssignCurrentUser', $actions[0]['action_name']); + $this->assertNotEmpty($actions[0]['params']); + $this->assertEquals(6, $actions[0]['params']['column_id']); + } + + public function testCloneProjectWithActionTaskAssignColorCategory() + { + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + $categoryModel = new CategoryModel($this->container); + $projectDuplicationModel = new ProjectDuplicationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + + $this->assertEquals(1, $categoryModel->create(array('name' => 'C1', 'project_id' => 1))); + $this->assertEquals(2, $categoryModel->create(array('name' => 'C2', 'project_id' => 1))); + $this->assertEquals(3, $categoryModel->create(array('name' => 'C3', 'project_id' => 1))); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => TaskModel::EVENT_CREATE_UPDATE, + 'action_name' => 'TaskAssignColorCategory', + 'params' => array('color_id' => 'blue', 'category_id' => 2), + ))); + + $this->assertEquals(2, $projectDuplicationModel->duplicate(1)); + + $actions = $actionModel->getAllByProject(2); + + $this->assertNotEmpty($actions); + $this->assertEquals('TaskAssignColorCategory', $actions[0]['action_name']); + $this->assertNotEmpty($actions[0]['params']); + $this->assertEquals('blue', $actions[0]['params']['color_id']); + $this->assertEquals(5, $actions[0]['params']['category_id']); + } + + public function testCloneProjectWithSwimlanes() + { + $projectModel = new ProjectModel($this->container); + $projectDuplicationModel = new ProjectDuplicationModel($this->container); + $swimlaneModel = new SwimlaneModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1', 'default_swimlane' => 'New Default'))); + + // create initial swimlanes + $this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'S1'))); + $this->assertEquals(2, $swimlaneModel->create(array('project_id' => 1, 'name' => 'S2'))); + $this->assertEquals(3, $swimlaneModel->create(array('project_id' => 1, 'name' => 'S3'))); + + // create initial tasks + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T0', 'project_id' => 1, 'swimlane_id' => 0))); + $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1, 'swimlane_id' => 1))); + $this->assertEquals(3, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'swimlane_id' => 2))); + $this->assertEquals(4, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'swimlane_id' => 3))); + + $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('categoryModel', 'swimlaneModel'))); + + $swimlanes = $swimlaneModel->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']); + + $swimlane = $swimlaneModel->getDefault(2); + $this->assertEquals('New Default', $swimlane['default_swimlane']); + + // Check if tasks are NOT been duplicated + $this->assertCount(0, $taskFinderModel->getAll(2)); + } + + public function testCloneProjectWithTasks() + { + $projectModel = new ProjectModel($this->container); + $projectDuplicationModel = new ProjectDuplicationModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + + // create initial tasks + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1))); + $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2))); + $this->assertEquals(3, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3))); + + $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('categoryModel', 'actionModel', 'taskModel'))); + + // Check if Tasks have been duplicated + $tasks = $taskFinderModel->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 testCloneProjectWithSwimlanesAndTasks() + { + $projectModel = new ProjectModel($this->container); + $projectDuplicationModel = new ProjectDuplicationModel($this->container); + $swimlaneModel = new SwimlaneModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1', 'default_swimlane' => 'New Default'))); + + // create initial swimlanes + $this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'S1'))); + $this->assertEquals(2, $swimlaneModel->create(array('project_id' => 1, 'name' => 'S2'))); + $this->assertEquals(3, $swimlaneModel->create(array('project_id' => 1, 'name' => 'S3'))); + + // create initial tasks + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); + $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1))); + $this->assertEquals(3, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); + + $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel', 'swimlaneModel', 'taskModel'))); + + // Check if Swimlanes have been duplicated + $swimlanes = $swimlaneModel->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']); + + $swimlane = $swimlaneModel->getDefault(2); + $this->assertEquals('New Default', $swimlane['default_swimlane']); + + // Check if Tasks have been duplicated + $tasks = $taskFinderModel->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 testCloneProjectWithTags() + { + $projectModel = new ProjectModel($this->container); + $projectDuplicationModel = new ProjectDuplicationModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $tagModel = new TagModel($this->container); + $taskTagModel = new TaskTagModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'tags' => array('A')))); + $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'tags' => array('A', 'B')))); + $this->assertEquals(3, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'tags' => array('C')))); + + $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('categoryModel', 'actionModel', 'tagDuplicationModel', 'taskModel'))); + + $tasks = $taskFinderModel->getAll(2); + $this->assertCount(3, $tasks); + $this->assertEquals('T1', $tasks[0]['title']); + $this->assertEquals('T2', $tasks[1]['title']); + $this->assertEquals('T3', $tasks[2]['title']); + + $tags = $tagModel->getAllByProject(2); + $this->assertCount(3, $tags); + $this->assertEquals(4, $tags[0]['id']); + $this->assertEquals('A', $tags[0]['name']); + $this->assertEquals(5, $tags[1]['id']); + $this->assertEquals('B', $tags[1]['name']); + $this->assertEquals(6, $tags[2]['id']); + $this->assertEquals('C', $tags[2]['name']); + + $tags = $taskTagModel->getList(4); + $this->assertEquals('A', $tags[4]); + + $tags = $taskTagModel->getList(5); + $this->assertEquals('A', $tags[4]); + $this->assertEquals('B', $tags[5]); + + $tags = $taskTagModel->getList(6); + $this->assertEquals('C', $tags[6]); + } +} diff --git a/tests/units/Model/ProjectDuplicationTest.php b/tests/units/Model/ProjectDuplicationTest.php deleted file mode 100644 index 312c7168..00000000 --- a/tests/units/Model/ProjectDuplicationTest.php +++ /dev/null @@ -1,482 +0,0 @@ -<?php - -require_once __DIR__.'/../Base.php'; - -use Kanboard\Model\ActionModel; -use Kanboard\Model\ProjectModel; -use Kanboard\Model\CategoryModel; -use Kanboard\Model\ProjectUserRoleModel; -use Kanboard\Model\ProjectGroupRoleModel; -use Kanboard\Model\ProjectDuplicationModel; -use Kanboard\Model\UserModel; -use Kanboard\Model\GroupModel; -use Kanboard\Model\GroupMemberModel; -use Kanboard\Model\SwimlaneModel; -use Kanboard\Model\TaskModel; -use Kanboard\Model\TaskCreationModel; -use Kanboard\Model\TaskFinderModel; -use Kanboard\Core\Security\Role; - -class ProjectDuplicationTest extends Base -{ - public function testGetSelections() - { - $projectDuplicationModel = new ProjectDuplicationModel($this->container); - $this->assertCount(6, $projectDuplicationModel->getOptionalSelection()); - $this->assertCount(7, $projectDuplicationModel->getPossibleSelection()); - } - - public function testGetClonedProjectName() - { - $pd = new ProjectDuplicationModel($this->container); - - $this->assertEquals('test (Clone)', $pd->getClonedProjectName('test')); - - $this->assertEquals(50, strlen($pd->getClonedProjectName(str_repeat('a', 50)))); - $this->assertEquals(str_repeat('a', 42).' (Clone)', $pd->getClonedProjectName(str_repeat('a', 50))); - - $this->assertEquals(50, strlen($pd->getClonedProjectName(str_repeat('a', 60)))); - $this->assertEquals(str_repeat('a', 42).' (Clone)', $pd->getClonedProjectName(str_repeat('a', 60))); - } - - public function testClonePublicProject() - { - $p = new ProjectModel($this->container); - $pd = new ProjectDuplicationModel($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'Public'))); - $this->assertEquals(2, $pd->duplicate(1)); - - $project = $p->getById(2); - $this->assertNotEmpty($project); - $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 testClonePrivateProject() - { - $p = new ProjectModel($this->container); - $pd = new ProjectDuplicationModel($this->container); - $pp = new ProjectUserRoleModel($this->container); - - $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('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 testCloneSharedProject() - { - $p = new ProjectModel($this->container); - $pd = new ProjectDuplicationModel($this->container); - - $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('Shared (Clone)', $project['name']); - $this->assertEquals('', $project['token']); - $this->assertEquals(0, $project['is_public']); - } - - public function testCloneInactiveProject() - { - $p = new ProjectModel($this->container); - $pd = new ProjectDuplicationModel($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 ProjectModel($this->container); - $pd = new ProjectDuplicationModel($this->container); - $projectUserRoleModel = new ProjectUserRoleModel($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('projectPermissionModel'), 1)); - - $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 ProjectModel($this->container); - $pd = new ProjectDuplicationModel($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('projectPermissionModel'), 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 ProjectModel($this->container); - $pd = new ProjectDuplicationModel($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('projectPermissionModel'), 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() - { - $p = new ProjectModel($this->container); - $c = new CategoryModel($this->container); - $pd = new ProjectDuplicationModel($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'P1'))); - - $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1))); - $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 1))); - $this->assertEquals(3, $c->create(array('name' => 'C3', 'project_id' => 1))); - - $this->assertEquals(2, $pd->duplicate(1)); - - $project = $p->getById(2); - $this->assertNotEmpty($project); - $this->assertEquals('P1 (Clone)', $project['name']); - - $categories = $c->getAll(2); - $this->assertCount(3, $categories); - $this->assertEquals('C1', $categories[0]['name']); - $this->assertEquals('C2', $categories[1]['name']); - $this->assertEquals('C3', $categories[2]['name']); - } - - public function testCloneProjectWithUsers() - { - $p = new ProjectModel($this->container); - $pp = new ProjectUserRoleModel($this->container); - $u = new UserModel($this->container); - $pd = new ProjectDuplicationModel($this->container); - - $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_MANAGER)); - $this->assertTrue($pp->addUser(1, 3, Role::PROJECT_MEMBER)); - $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 ProjectModel($this->container); - $pp = new ProjectUserRoleModel($this->container); - $u = new UserModel($this->container); - $pd = new ProjectDuplicationModel($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('projectPermissionModel'), 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->assertEquals(1, $project['owner_id']); - } - - public function testCloneTeamProjectToPrivatProject() - { - $p = new ProjectModel($this->container); - $pp = new ProjectUserRoleModel($this->container); - $u = new UserModel($this->container); - $pd = new ProjectDuplicationModel($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('projectPermissionModel'), 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 ProjectModel($this->container); - $pd = new ProjectDuplicationModel($this->container); - $userModel = new UserModel($this->container); - $groupModel = new GroupModel($this->container); - $groupMemberModel = new GroupMemberModel($this->container); - $projectGroupRoleModel = new ProjectGroupRoleModel($this->container); - $projectUserRoleModel = new ProjectUserRoleModel($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() - { - $p = new ProjectModel($this->container); - $a = new ActionModel($this->container); - $pd = new ProjectDuplicationModel($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'P1'))); - - $this->assertEquals(1, $a->create(array( - 'project_id' => 1, - 'event_name' => TaskModel::EVENT_MOVE_COLUMN, - 'action_name' => 'TaskAssignCurrentUser', - 'params' => array('column_id' => 2), - ))); - - $this->assertEquals(2, $pd->duplicate(1)); - - $actions = $a->getAllByProject(2); - - $this->assertNotEmpty($actions); - $this->assertEquals('TaskAssignCurrentUser', $actions[0]['action_name']); - $this->assertNotEmpty($actions[0]['params']); - $this->assertEquals(6, $actions[0]['params']['column_id']); - } - - public function testCloneProjectWithActionTaskAssignColorCategory() - { - $p = new ProjectModel($this->container); - $a = new ActionModel($this->container); - $c = new CategoryModel($this->container); - $pd = new ProjectDuplicationModel($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'P1'))); - - $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1))); - $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 1))); - $this->assertEquals(3, $c->create(array('name' => 'C3', 'project_id' => 1))); - - $this->assertEquals(1, $a->create(array( - 'project_id' => 1, - 'event_name' => TaskModel::EVENT_CREATE_UPDATE, - 'action_name' => 'TaskAssignColorCategory', - 'params' => array('color_id' => 'blue', 'category_id' => 2), - ))); - - $this->assertEquals(2, $pd->duplicate(1)); - - $actions = $a->getAllByProject(2); - - $this->assertNotEmpty($actions); - $this->assertEquals('TaskAssignColorCategory', $actions[0]['action_name']); - $this->assertNotEmpty($actions[0]['params']); - $this->assertEquals('blue', $actions[0]['params']['color_id']); - $this->assertEquals(5, $actions[0]['params']['category_id']); - } - - public function testCloneProjectWithSwimlanes() - { - $p = new ProjectModel($this->container); - $pd = new ProjectDuplicationModel($this->container); - $s = new SwimlaneModel($this->container); - $tc = new TaskCreationModel($this->container); - $tf = new TaskFinderModel($this->container); - - $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'))); - - // 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))); - - $this->assertEquals(2, $pd->duplicate(1, array('categoryModel', 'swimlaneModel'))); - - $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']); - - $swimlane = $s->getDefault(2); - $this->assertEquals('New Default', $swimlane['default_swimlane']); - - // Check if tasks are NOT been duplicated - $this->assertCount(0, $tf->getAll(2)); - } - - public function testCloneProjectWithTasks() - { - $p = new ProjectModel($this->container); - $pd = new ProjectDuplicationModel($this->container); - $tc = new TaskCreationModel($this->container); - $tf = new TaskFinderModel($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'P1'))); - - // 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))); - - $this->assertEquals(2, $pd->duplicate(1, array('categoryModel', 'actionModel', 'taskModel'))); - - // 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 testCloneProjectWithSwimlanesAndTasks() - { - $p = new ProjectModel($this->container); - $pd = new ProjectDuplicationModel($this->container); - $s = new SwimlaneModel($this->container); - $tc = new TaskCreationModel($this->container); - $tf = new TaskFinderModel($this->container); - - $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'))); - - // 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->assertEquals(2, $pd->duplicate(1, array('projectPermissionModel', 'swimlaneModel', 'taskModel'))); - - // 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']); - - $swimlane = $s->getDefault(2); - $this->assertEquals('New Default', $swimlane['default_swimlane']); - - // 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']); - } -} diff --git a/tests/units/Model/TagDuplicationModelTest.php b/tests/units/Model/TagDuplicationModelTest.php new file mode 100644 index 00000000..0c95c0fd --- /dev/null +++ b/tests/units/Model/TagDuplicationModelTest.php @@ -0,0 +1,31 @@ +<?php + +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TagDuplicationModel; +use Kanboard\Model\TagModel; + +require_once __DIR__.'/../Base.php'; + +class TagDuplicationModelTest extends Base +{ + public function testProjectDuplication() + { + $tagModel = new TagModel($this->container); + $tagDuplicationModel = new TagDuplicationModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'P2'))); + + $this->assertEquals(1, $tagModel->create(0, 'Tag 1')); + $this->assertEquals(2, $tagModel->create(1, 'Tag 2')); + $this->assertEquals(3, $tagModel->create(1, 'Tag 3')); + + $this->assertTrue($tagDuplicationModel->duplicate(1, 2)); + + $tags = $tagModel->getAllByProject(2); + $this->assertCount(2, $tags); + $this->assertEquals('Tag 2', $tags[0]['name']); + $this->assertEquals('Tag 3', $tags[1]['name']); + } +} |