1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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']);
}
}
|