diff options
Diffstat (limited to 'tests/units/TaskLinkTest.php')
-rw-r--r-- | tests/units/TaskLinkTest.php | 105 |
1 files changed, 91 insertions, 14 deletions
diff --git a/tests/units/TaskLinkTest.php b/tests/units/TaskLinkTest.php index b78ffd28..e213e25a 100644 --- a/tests/units/TaskLinkTest.php +++ b/tests/units/TaskLinkTest.php @@ -18,9 +18,9 @@ class TaskLinkTest extends Base $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B'))); - $this->assertTrue($tl->create(1, 2, 1)); + $this->assertEquals(1, $tl->create(1, 2, 1)); - $links = $tl->getLinks(1); + $links = $tl->getAll(1); $this->assertNotEmpty($links); $this->assertCount(1, $links); $this->assertEquals('relates to', $links[0]['label']); @@ -28,13 +28,27 @@ class TaskLinkTest extends Base $this->assertEquals(2, $links[0]['task_id']); $this->assertEquals(1, $links[0]['is_active']); - $links = $tl->getLinks(2); + $links = $tl->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 = $tl->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 = $tl->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() @@ -46,9 +60,9 @@ class TaskLinkTest extends Base $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B'))); - $this->assertTrue($tl->create(1, 2, 2)); + $this->assertEquals(1, $tl->create(1, 2, 2)); - $links = $tl->getLinks(1); + $links = $tl->getAll(1); $this->assertNotEmpty($links); $this->assertCount(1, $links); $this->assertEquals('blocks', $links[0]['label']); @@ -56,13 +70,60 @@ class TaskLinkTest extends Base $this->assertEquals(2, $links[0]['task_id']); $this->assertEquals(1, $links[0]['is_active']); - $links = $tl->getLinks(2); + $links = $tl->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 = $tl->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 = $tl->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 testUpdate() + { + $tl = new TaskLink($this->container); + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test1'))); + $this->assertEquals(2, $p->create(array('name' => 'test2'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); + $this->assertEquals(2, $tc->create(array('project_id' => 2, 'title' => 'B'))); + $this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'C'))); + + $this->assertEquals(1, $tl->create(1, 2, 5)); + $this->assertTrue($tl->update(1, 1, 3, 11)); + + $links = $tl->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 = $tl->getAll(2); + $this->assertEmpty($links); + + $links = $tl->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() @@ -74,35 +135,51 @@ class TaskLinkTest extends Base $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B'))); - $this->assertTrue($tl->create(1, 2, 2)); + $this->assertEquals(1, $tl->create(1, 2, 2)); - $links = $tl->getLinks(1); + $links = $tl->getAll(1); $this->assertNotEmpty($links); - $links = $tl->getLinks(2); + $links = $tl->getAll(2); $this->assertNotEmpty($links); $this->assertTrue($tl->remove($links[0]['id'])); - $links = $tl->getLinks(1); + $links = $tl->getAll(1); $this->assertEmpty($links); - $links = $tl->getLinks(2); + $links = $tl->getAll(2); $this->assertEmpty($links); } public function testValidation() { $tl = new TaskLink($this->container); + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); + $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B'))); + + $links = $tl->getAll(1); + $this->assertEmpty($links); - $r = $tl->validateCreation(array('task_id' => 1, 'link_id' => 1, 'title' => 'a')); + $links = $tl->getAll(2); + $this->assertEmpty($links); + + // Check validation + $r = $tl->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 2)); $this->assertTrue($r[0]); $r = $tl->validateCreation(array('task_id' => 1, 'link_id' => 1)); $this->assertFalse($r[0]); - $r = $tl->validateCreation(array('task_id' => 1, 'title' => 'a')); + $r = $tl->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2)); + $this->assertFalse($r[0]); + + $r = $tl->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2)); $this->assertFalse($r[0]); - $r = $tl->validateCreation(array('link_id' => 1, 'title' => 'a')); + $r = $tl->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 1)); $this->assertFalse($r[0]); } } |