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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
<?php
require_once __DIR__.'/../Base.php';
use Kanboard\Model\Config;
use Kanboard\Model\TaskCreation;
use Kanboard\Model\TaskFinder;
use Kanboard\Model\Project;
use Kanboard\Model\Category;
class CategoryTest extends Base
{
public function testCreation()
{
$taskCreationModel = new TaskCreation($this->container);
$taskFinderModel = new TaskFinder($this->container);
$projectModel = new Project($this->container);
$categoryModel = new Category($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
$this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1)));
$this->assertEquals(2, $categoryModel->create(array('name' => 'Category #2', 'project_id' => 1)));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2)));
$task = $taskFinderModel->getById(1);
$this->assertEquals(2, $task['category_id']);
$category = $categoryModel->getById(2);
$this->assertEquals(2, $category['id']);
$this->assertEquals('Category #2', $category['name']);
$this->assertEquals(1, $category['project_id']);
}
public function testExists()
{
$projectModel = new Project($this->container);
$categoryModel = new Category($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
$this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1)));
$this->assertTrue($categoryModel->exists(1));
$this->assertFalse($categoryModel->exists(2));
}
public function testGetById()
{
$projectModel = new Project($this->container);
$categoryModel = new Category($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
$this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test')));
$category = $categoryModel->getById(1);
$this->assertEquals(1, $category['id']);
$this->assertEquals('Category #1', $category['name']);
$this->assertEquals(1, $category['project_id']);
$this->assertEquals('test', $category['description']);
}
public function testGetNameById()
{
$projectModel = new Project($this->container);
$categoryModel = new Category($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
$this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test')));
$this->assertEquals('Category #1', $categoryModel->getNameById(1));
$this->assertEquals('', $categoryModel->getNameById(2));
}
public function testGetIdByName()
{
$projectModel = new Project($this->container);
$categoryModel = new Category($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
$this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test')));
$this->assertSame(1, $categoryModel->getIdByName(1, 'Category #1'));
$this->assertSame(0, $categoryModel->getIdByName(1, 'Category #2'));
}
public function testGetList()
{
$projectModel = new Project($this->container);
$categoryModel = new Category($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
$this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test')));
$this->assertEquals(2, $categoryModel->create(array('name' => 'Category #2', 'project_id' => 1)));
$categories = $categoryModel->getList(1, false, false);
$this->assertCount(2, $categories);
$this->assertEquals('Category #1', $categories[1]);
$this->assertEquals('Category #2', $categories[2]);
$categories = $categoryModel->getList(1, true, false);
$this->assertCount(3, $categories);
$this->assertEquals('No category', $categories[0]);
$this->assertEquals('Category #1', $categories[1]);
$this->assertEquals('Category #2', $categories[2]);
$categories = $categoryModel->getList(1, false, true);
$this->assertCount(3, $categories);
$this->assertEquals('All categories', $categories[-1]);
$this->assertEquals('Category #1', $categories[1]);
$this->assertEquals('Category #2', $categories[2]);
$categories = $categoryModel->getList(1, true, true);
$this->assertCount(4, $categories);
$this->assertEquals('All categories', $categories[-1]);
$this->assertEquals('No category', $categories[0]);
$this->assertEquals('Category #1', $categories[1]);
$this->assertEquals('Category #2', $categories[2]);
}
public function testGetAll()
{
$projectModel = new Project($this->container);
$categoryModel = new Category($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
$this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test')));
$this->assertEquals(2, $categoryModel->create(array('name' => 'Category #2', 'project_id' => 1)));
$categories = $categoryModel->getAll(1);
$this->assertCount(2, $categories);
$this->assertEquals('Category #1', $categories[0]['name']);
$this->assertEquals('test', $categories[0]['description']);
$this->assertEquals(1, $categories[0]['project_id']);
$this->assertEquals(1, $categories[0]['id']);
$this->assertEquals('Category #2', $categories[1]['name']);
$this->assertEquals('', $categories[1]['description']);
$this->assertEquals(1, $categories[1]['project_id']);
$this->assertEquals(2, $categories[1]['id']);
}
public function testCreateDefaultCategories()
{
$projectModel = new Project($this->container);
$categoryModel = new Category($this->container);
$configModel = new Config($this->container);
$this->assertTrue($configModel->save(array('project_categories' => 'C1, C2, C3')));
$this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
$this->assertTrue($categoryModel->createDefaultCategories(1));
$categories = $categoryModel->getAll(1);
$this->assertCount(3, $categories);
$this->assertEquals('C1', $categories[0]['name']);
$this->assertEquals('C2', $categories[1]['name']);
$this->assertEquals('C3', $categories[2]['name']);
}
public function testUpdate()
{
$projectModel = new Project($this->container);
$categoryModel = new Category($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
$this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1)));
$this->assertTrue($categoryModel->update(array('id' => 1, 'description' => 'test')));
$category = $categoryModel->getById(1);
$this->assertEquals('Category #1', $category['name']);
$this->assertEquals(1, $category['project_id']);
$this->assertEquals('test', $category['description']);
}
public function testRemove()
{
$taskCreationModel = new TaskCreation($this->container);
$taskFinderModel = new TaskFinder($this->container);
$projectModel = new Project($this->container);
$categoryModel = new Category($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
$this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1)));
$this->assertEquals(2, $categoryModel->create(array('name' => 'Category #2', 'project_id' => 1)));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2)));
$task = $taskFinderModel->getById(1);
$this->assertEquals(2, $task['category_id']);
$this->assertTrue($categoryModel->remove(1));
$this->assertTrue($categoryModel->remove(2));
// Make sure tasks assigned with that category are reseted
$task = $taskFinderModel->getById(1);
$this->assertEquals(0, $task['category_id']);
}
public function testDuplicate()
{
$projectModel = new Project($this->container);
$categoryModel = new Category($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'Project #2')));
$this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test')));
$this->assertTrue($categoryModel->duplicate(1, 2));
$category = $categoryModel->getById(1);
$this->assertEquals('Category #1', $category['name']);
$this->assertEquals(1, $category['project_id']);
$this->assertEquals('test', $category['description']);
$category = $categoryModel->getById(2);
$this->assertEquals('Category #1', $category['name']);
$this->assertEquals(2, $category['project_id']);
$this->assertEquals('test', $category['description']);
}
}
|