Refactoring/simplification of the pull-request about links
This commit is contained in:
161
tests/units/LinkTest.php
Normal file
161
tests/units/LinkTest.php
Normal file
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/Base.php';
|
||||
|
||||
use Model\Link;
|
||||
|
||||
class LinkTest extends Base
|
||||
{
|
||||
public function testCreateLink()
|
||||
{
|
||||
$l = new Link($this->container);
|
||||
|
||||
$this->assertTrue($l->create('Link A'));
|
||||
$this->assertFalse($l->create('Link A'));
|
||||
$this->assertTrue($l->create('Link B', 'Link C'));
|
||||
|
||||
$links = $l->getAll();
|
||||
$this->assertNotEmpty($links);
|
||||
$this->assertCount(14, $links);
|
||||
|
||||
$link = $l->getByLabel('Link A');
|
||||
$this->assertNotEmpty($link);
|
||||
$this->assertEquals('Link A', $link['label']);
|
||||
$this->assertEquals(0, $link['opposite_id']);
|
||||
|
||||
$link1 = $l->getByLabel('Link B');
|
||||
$this->assertNotEmpty($link1);
|
||||
$this->assertEquals('Link B', $link1['label']);
|
||||
$this->assertNotEmpty($link1['opposite_id']);
|
||||
|
||||
$link2 = $l->getByLabel('Link C');
|
||||
$this->assertNotEmpty($link2);
|
||||
$this->assertEquals('Link C', $link2['label']);
|
||||
$this->assertNotEmpty($link2['opposite_id']);
|
||||
|
||||
$this->assertNotEquals($link1['opposite_id'], $link2['opposite_id']);
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$l = new Link($this->container);
|
||||
|
||||
$this->assertTrue($l->update(array('id' => 2, 'label' => 'test', 'opposite_id' => 0)));
|
||||
|
||||
$link = $l->getById(2);
|
||||
$this->assertNotEmpty($link);
|
||||
$this->assertEquals('test', $link['label']);
|
||||
$this->assertEquals(0, $link['opposite_id']);
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$l = new Link($this->container);
|
||||
|
||||
$link = $l->getById(3);
|
||||
$this->assertNotEmpty($link);
|
||||
$this->assertEquals('is blocked by', $link['label']);
|
||||
$this->assertEquals(2, $link['opposite_id']);
|
||||
|
||||
$this->assertTrue($l->remove(2));
|
||||
|
||||
$link = $l->getById(2);
|
||||
$this->assertEmpty($link);
|
||||
|
||||
$link = $l->getById(3);
|
||||
$this->assertNotEmpty($link);
|
||||
$this->assertEquals('is blocked by', $link['label']);
|
||||
$this->assertEquals(0, $link['opposite_id']);
|
||||
}
|
||||
|
||||
public function testGetMergedList()
|
||||
{
|
||||
$l = new Link($this->container);
|
||||
$links = $l->getMergedList();
|
||||
|
||||
$this->assertNotEmpty($links);
|
||||
$this->assertCount(11, $links);
|
||||
$this->assertEquals('blocks', $links[1]['label']);
|
||||
$this->assertEquals('is blocked by', $links[1]['opposite_label']);
|
||||
}
|
||||
|
||||
public function testGetList()
|
||||
{
|
||||
$l = new Link($this->container);
|
||||
$links = $l->getList();
|
||||
|
||||
$this->assertNotEmpty($links);
|
||||
$this->assertCount(12, $links);
|
||||
$this->assertEquals('', $links[0]);
|
||||
$this->assertEquals('relates to', $links[1]);
|
||||
|
||||
$links = $l->getList(1);
|
||||
|
||||
$this->assertNotEmpty($links);
|
||||
$this->assertCount(11, $links);
|
||||
$this->assertEquals('', $links[0]);
|
||||
$this->assertArrayNotHasKey(1, $links);
|
||||
$this->assertEquals('blocks', $links[2]);
|
||||
|
||||
$links = $l->getList(1, false);
|
||||
|
||||
$this->assertNotEmpty($links);
|
||||
$this->assertCount(10, $links);
|
||||
$this->assertArrayNotHasKey(0, $links);
|
||||
$this->assertArrayNotHasKey(1, $links);
|
||||
$this->assertEquals('blocks', $links[2]);
|
||||
|
||||
$links = $l->getList(0, false);
|
||||
|
||||
$this->assertNotEmpty($links);
|
||||
$this->assertCount(11, $links);
|
||||
$this->assertArrayNotHasKey(0, $links);
|
||||
$this->assertEquals('relates to', $links[1]);
|
||||
}
|
||||
|
||||
public function testValidateCreation()
|
||||
{
|
||||
$l = new Link($this->container);
|
||||
|
||||
$r = $l->validateCreation(array('label' => 'a'));
|
||||
$this->assertTrue($r[0]);
|
||||
|
||||
$r = $l->validateCreation(array('label' => 'a', 'opposite_label' => 'b'));
|
||||
$this->assertTrue($r[0]);
|
||||
|
||||
$r = $l->validateCreation(array('label' => 'relates to'));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $l->validateCreation(array('label' => 'a', 'opposite_label' => 'a'));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $l->validateCreation(array('label' => ''));
|
||||
$this->assertFalse($r[0]);
|
||||
}
|
||||
|
||||
public function testValidateModification()
|
||||
{
|
||||
$l = new Link($this->container);
|
||||
|
||||
$r = $l->validateModification(array('id' => 20, 'label' => 'a', 'opposite_id' => 0));
|
||||
$this->assertTrue($r[0]);
|
||||
|
||||
$r = $l->validateModification(array('id' => 20, 'label' => 'a', 'opposite_id' => '1'));
|
||||
$this->assertTrue($r[0]);
|
||||
|
||||
$r = $l->validateModification(array('id' => 20, 'label' => 'relates to', 'opposite_id' => '1'));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $l->validateModification(array('id' => 20, 'label' => '', 'opposite_id' => '1'));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $l->validateModification(array('label' => '', 'opposite_id' => '1'));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $l->validateModification(array('id' => 20, 'opposite_id' => '1'));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $l->validateModification(array('label' => 'test'));
|
||||
$this->assertFalse($r[0]);
|
||||
}
|
||||
}
|
||||
108
tests/units/TaskLinkTest.php
Normal file
108
tests/units/TaskLinkTest.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/Base.php';
|
||||
|
||||
use Model\Link;
|
||||
use Model\TaskLink;
|
||||
use Model\TaskCreation;
|
||||
use Model\Project;
|
||||
|
||||
class TaskLinkTest extends Base
|
||||
{
|
||||
public function testCreateTaskLinkWithNoOpposite()
|
||||
{
|
||||
$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')));
|
||||
$this->assertTrue($tl->create(1, 2, 1));
|
||||
|
||||
$links = $tl->getLinks(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 = $tl->getLinks(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']);
|
||||
}
|
||||
|
||||
public function testCreateTaskLinkWithOpposite()
|
||||
{
|
||||
$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')));
|
||||
$this->assertTrue($tl->create(1, 2, 2));
|
||||
|
||||
$links = $tl->getLinks(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 = $tl->getLinks(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']);
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$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')));
|
||||
$this->assertTrue($tl->create(1, 2, 2));
|
||||
|
||||
$links = $tl->getLinks(1);
|
||||
$this->assertNotEmpty($links);
|
||||
$links = $tl->getLinks(2);
|
||||
$this->assertNotEmpty($links);
|
||||
|
||||
$this->assertTrue($tl->remove($links[0]['id']));
|
||||
|
||||
$links = $tl->getLinks(1);
|
||||
$this->assertEmpty($links);
|
||||
$links = $tl->getLinks(2);
|
||||
$this->assertEmpty($links);
|
||||
}
|
||||
|
||||
public function testValidation()
|
||||
{
|
||||
$tl = new TaskLink($this->container);
|
||||
|
||||
$r = $tl->validateCreation(array('task_id' => 1, 'link_id' => 1, 'title' => 'a'));
|
||||
$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'));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $tl->validateCreation(array('link_id' => 1, 'title' => 'a'));
|
||||
$this->assertFalse($r[0]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user