diff options
| author | Teamjungla{CODE} <junglacode@gmail.com> | 2016-08-20 13:47:12 -0500 |
|---|---|---|
| committer | Teamjungla{CODE} <junglacode@gmail.com> | 2016-08-20 13:47:12 -0500 |
| commit | fe8e9cdcfe3afc1475c7e7f4392d2b2cc601a12b (patch) | |
| tree | 001403874e9e3716de7c6d51a9f536e9b3c3be5e /tests/units/Model/TaskDuplicationModelTest.php | |
| parent | b1e795fc5b45369f7b9b565b1e106d2673361977 (diff) | |
| parent | 98efcf21e355ed6ac3827058b99df86ca67c75bb (diff) | |
Merge branch 'stable' of https://github.com/kanboard/kanboard
Diffstat (limited to 'tests/units/Model/TaskDuplicationModelTest.php')
| -rw-r--r-- | tests/units/Model/TaskDuplicationModelTest.php | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/tests/units/Model/TaskDuplicationModelTest.php b/tests/units/Model/TaskDuplicationModelTest.php new file mode 100644 index 00000000..1c42b6a1 --- /dev/null +++ b/tests/units/Model/TaskDuplicationModelTest.php @@ -0,0 +1,142 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskDuplicationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\CategoryModel; +use Kanboard\Model\TaskTagModel; + +class TaskDuplicationModelTest extends Base +{ + public function testThatDuplicateDefineCreator() + { + $taskDuplicationModel = new TaskDuplicationModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1))); + + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['position']); + $this->assertEquals(1, $task['project_id']); + $this->assertEquals(0, $task['creator_id']); + + $this->container['sessionStorage']->user = array('id' => 1); + + // We duplicate our task + $this->assertEquals(2, $taskDuplicationModel->duplicate(1)); + + // Check the values of the duplicated task + $task = $taskFinderModel->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['creator_id']); + } + + public function testDuplicateSameProject() + { + $taskDuplicationModel = new TaskDuplicationModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); + + // We create a task and a project + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + + // Some categories + $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); + $this->assertNotFalse($categoryModel->create(array('name' => 'Category #2', 'project_id' => 1))); + $this->assertTrue($categoryModel->exists(1)); + $this->assertTrue($categoryModel->exists(2)); + + $this->assertEquals(1, $taskCreationModel->create(array( + 'title' => 'test', + 'project_id' => 1, + 'column_id' => 3, + 'owner_id' => 1, + 'category_id' => 2, + 'time_spent' => 4.4 + ))); + + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['position']); + $this->assertEquals(1, $task['project_id']); + $this->assertEquals(3, $task['column_id']); + $this->assertEquals(2, $task['category_id']); + $this->assertEquals(4.4, $task['time_spent']); + + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {}); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function () {}); + + // We duplicate our task + $this->assertEquals(2, $taskDuplicationModel->duplicate(1)); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called); + + // Check the values of the duplicated task + $task = $taskFinderModel->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(TaskModel::STATUS_OPEN, $task['is_active']); + $this->assertEquals(1, $task['project_id']); + $this->assertEquals(1, $task['owner_id']); + $this->assertEquals(2, $task['category_id']); + $this->assertEquals(0, $task['swimlane_id']); + $this->assertEquals(3, $task['column_id']); + $this->assertEquals(2, $task['position']); + $this->assertEquals('test', $task['title']); + $this->assertEquals(0, $task['time_spent']); + } + + public function testDuplicateSameProjectWithTags() + { + $taskDuplicationModel = new TaskDuplicationModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskTagModel = new TaskTagModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array( + 'title' => 'test', + 'project_id' => 1, + 'tags' => array('T1', 'T2') + ))); + + $this->assertEquals(2, $taskDuplicationModel->duplicate(1)); + + $tags = $taskTagModel->getList(2); + $this->assertCount(2, $tags); + $this->assertArrayHasKey(1, $tags); + $this->assertArrayHasKey(2, $tags); + } + + public function testDuplicateSameProjectWithPriority() + { + $taskDuplicationModel = new TaskDuplicationModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array( + 'title' => 'test', + 'project_id' => 1, + 'priority' => 2 + ))); + + $this->assertEquals(2, $taskDuplicationModel->duplicate(1)); + + $task = $taskFinderModel->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(2, $task['priority']); + } +} |
