File size: 11,118 Bytes
e4f4821 |
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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
<?php
require_once __DIR__.'/../Base.php';
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\TaskLinkModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\ProjectModel;
class TaskLinkModelTest extends Base
{
public function testGeyById()
{
$taskLinkModel = new TaskLinkModel($this->container);
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
$this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
$this->assertEquals(1, $taskLinkModel->create(1, 2, 6));
$taskLink = $taskLinkModel->getById(1);
$this->assertEquals(1, $taskLink['id']);
$this->assertEquals(1, $taskLink['task_id']);
$this->assertEquals(2, $taskLink['opposite_task_id']);
$this->assertEquals(6, $taskLink['link_id']);
$this->assertEquals(7, $taskLink['opposite_link_id']);
$this->assertEquals('is a child of', $taskLink['label']);
$taskLink = $taskLinkModel->getById(2);
$this->assertEquals(2, $taskLink['id']);
$this->assertEquals(2, $taskLink['task_id']);
$this->assertEquals(1, $taskLink['opposite_task_id']);
$this->assertEquals(7, $taskLink['link_id']);
$this->assertEquals(6, $taskLink['opposite_link_id']);
$this->assertEquals('is a parent of', $taskLink['label']);
}
// Check postgres issue: "Cardinality violation: 7 ERROR: more than one row returned by a subquery used as an expression"
public function testGetTaskWithMultipleMilestoneLink()
{
$taskFinderModel = new TaskFinderModel($this->container);
$taskLinkModel = new TaskLinkModel($this->container);
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
$this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
$this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'C')));
$this->assertNotFalse($taskLinkModel->create(1, 2, 9));
$this->assertNotFalse($taskLinkModel->create(1, 3, 9));
$task = $taskFinderModel->getExtendedQuery()->findOne();
$this->assertNotEmpty($task);
}
public function testCreateTaskLinkWithNoOpposite()
{
$taskLinkModel = new TaskLinkModel($this->container);
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
$this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
$this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
$links = $taskLinkModel->getAll(1);
$this->assertNotEmpty($links);
$this->assertCount(1, $links);
$this->assertEquals('relates to', $links[0]['label']);
$this->assertEquals('B', $links[0]['title']);
$this->assertEquals(2, $links[0]['task_id']);
$this->assertEquals(1, $links[0]['is_active']);
$links = $taskLinkModel->getAll(2);
$this->assertNotEmpty($links);
$this->assertCount(1, $links);
$this->assertEquals('relates to', $links[0]['label']);
$this->assertEquals('A', $links[0]['title']);
$this->assertEquals(1, $links[0]['task_id']);
$this->assertEquals(1, $links[0]['is_active']);
$task_link = $taskLinkModel->getById(1);
$this->assertNotEmpty($task_link);
$this->assertEquals(1, $task_link['id']);
$this->assertEquals(1, $task_link['task_id']);
$this->assertEquals(2, $task_link['opposite_task_id']);
$this->assertEquals(1, $task_link['link_id']);
$opposite_task_link = $taskLinkModel->getOppositeTaskLink($task_link);
$this->assertNotEmpty($opposite_task_link);
$this->assertEquals(2, $opposite_task_link['id']);
$this->assertEquals(2, $opposite_task_link['task_id']);
$this->assertEquals(1, $opposite_task_link['opposite_task_id']);
$this->assertEquals(1, $opposite_task_link['link_id']);
}
public function testCreateTaskLinkWithOpposite()
{
$taskLinkModel = new TaskLinkModel($this->container);
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
$this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
$this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
$links = $taskLinkModel->getAll(1);
$this->assertNotEmpty($links);
$this->assertCount(1, $links);
$this->assertEquals('blocks', $links[0]['label']);
$this->assertEquals('B', $links[0]['title']);
$this->assertEquals(2, $links[0]['task_id']);
$this->assertEquals(1, $links[0]['is_active']);
$links = $taskLinkModel->getAll(2);
$this->assertNotEmpty($links);
$this->assertCount(1, $links);
$this->assertEquals('is blocked by', $links[0]['label']);
$this->assertEquals('A', $links[0]['title']);
$this->assertEquals(1, $links[0]['task_id']);
$this->assertEquals(1, $links[0]['is_active']);
$task_link = $taskLinkModel->getById(1);
$this->assertNotEmpty($task_link);
$this->assertEquals(1, $task_link['id']);
$this->assertEquals(1, $task_link['task_id']);
$this->assertEquals(2, $task_link['opposite_task_id']);
$this->assertEquals(2, $task_link['link_id']);
$opposite_task_link = $taskLinkModel->getOppositeTaskLink($task_link);
$this->assertNotEmpty($opposite_task_link);
$this->assertEquals(2, $opposite_task_link['id']);
$this->assertEquals(2, $opposite_task_link['task_id']);
$this->assertEquals(1, $opposite_task_link['opposite_task_id']);
$this->assertEquals(3, $opposite_task_link['link_id']);
}
public function testGroupByLabel()
{
$taskLinkModel = new TaskLinkModel($this->container);
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
$this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
$this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'C')));
$this->assertNotFalse($taskLinkModel->create(1, 2, 2));
$this->assertNotFalse($taskLinkModel->create(1, 3, 2));
$links = $taskLinkModel->getAllGroupedByLabel(1);
$this->assertCount(1, $links);
$this->assertArrayHasKey('blocks', $links);
$this->assertCount(2, $links['blocks']);
$this->assertEquals('test', $links['blocks'][0]['project_name']);
$this->assertEquals('Backlog', $links['blocks'][0]['column_title']);
$this->assertEquals('blocks', $links['blocks'][0]['label']);
}
public function testUpdate()
{
$taskLinkModel = new TaskLinkModel($this->container);
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
$this->assertEquals(2, $taskCreationModel->create(array('project_id' => 2, 'title' => 'B')));
$this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'C')));
$this->assertEquals(1, $taskLinkModel->create(1, 2, 5));
$this->assertTrue($taskLinkModel->update(1, 1, 3, 11));
$links = $taskLinkModel->getAll(1);
$this->assertNotEmpty($links);
$this->assertCount(1, $links);
$this->assertEquals('is fixed by', $links[0]['label']);
$this->assertEquals('C', $links[0]['title']);
$this->assertEquals(3, $links[0]['task_id']);
$links = $taskLinkModel->getAll(2);
$this->assertEmpty($links);
$links = $taskLinkModel->getAll(3);
$this->assertNotEmpty($links);
$this->assertCount(1, $links);
$this->assertEquals('fixes', $links[0]['label']);
$this->assertEquals('A', $links[0]['title']);
$this->assertEquals(1, $links[0]['task_id']);
}
public function testRemove()
{
$taskLinkModel = new TaskLinkModel($this->container);
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
$this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
$this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
$links = $taskLinkModel->getAll(1);
$this->assertNotEmpty($links);
$links = $taskLinkModel->getAll(2);
$this->assertNotEmpty($links);
$this->assertTrue($taskLinkModel->remove($links[0]['id']));
$links = $taskLinkModel->getAll(1);
$this->assertEmpty($links);
$links = $taskLinkModel->getAll(2);
$this->assertEmpty($links);
}
public function testGetProjectId()
{
$taskLinkModel = new TaskLinkModel($this->container);
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
$this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
$this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
$this->assertEquals(1, $taskLinkModel->getProjectId(1));
$this->assertEquals(0, $taskLinkModel->getProjectId(42));
}
}
|