diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-11-22 10:05:44 -0500 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-11-22 10:05:44 -0500 |
commit | 15038cdb10f8c691edc7980fd1aed32dcbed3f9f (patch) | |
tree | ebdf873e5c65616c3fd36ea2c7a449da52a61877 /tests/units/TaskCreationTest.php | |
parent | 8f0e544cd91b24423951bbb5d3f3be0950a63abe (diff) |
Move task creation to a seperate class
Diffstat (limited to 'tests/units/TaskCreationTest.php')
-rw-r--r-- | tests/units/TaskCreationTest.php | 330 |
1 files changed, 330 insertions, 0 deletions
diff --git a/tests/units/TaskCreationTest.php b/tests/units/TaskCreationTest.php new file mode 100644 index 00000000..48742a19 --- /dev/null +++ b/tests/units/TaskCreationTest.php @@ -0,0 +1,330 @@ +<?php + +require_once __DIR__.'/Base.php'; + +use Model\Task; +use Model\TaskCreation; +use Model\TaskFinder; +use Model\TaskStatus; +use Model\Project; +use Model\ProjectPermission; + +class TaskCreationTest extends Base +{ + public function testNoProjectId() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(0, $tc->create(array('title' => 'test', 'project_id' => 0))); + + $this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE)); + $this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_CREATE)); + } + + public function testNoTitle() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(0, $tc->create(array('project_id' => 1))); + + $this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE)); + $this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_CREATE)); + } + + public function testMinimum() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); + + $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE)); + $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE)); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(1, $task['id']); + $this->assertEquals('yellow', $task['color_id']); + $this->assertEquals(1, $task['project_id']); + $this->assertEquals(1, $task['column_id']); + $this->assertEquals(0, $task['owner_id']); + $this->assertEquals(0, $task['category_id']); + $this->assertEquals(0, $task['creator_id']); + + $this->assertEquals('test', $task['title']); + $this->assertEquals('', $task['description']); + $this->assertEquals('', $task['reference']); + + $this->assertEquals(time(), $task['date_creation']); + $this->assertEquals(time(), $task['date_modification']); + $this->assertEquals(0, $task['date_due']); + $this->assertEquals(0, $task['date_completed']); + $this->assertEquals(0, $task['date_started']); + + $this->assertEquals(0, $task['time_estimated']); + $this->assertEquals(0, $task['time_spent']); + + $this->assertEquals(1, $task['position']); + $this->assertEquals(1, $task['is_active']); + $this->assertEquals(0, $task['score']); + } + + public function testColorId() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'color_id' => 'blue'))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(1, $task['id']); + $this->assertEquals('blue', $task['color_id']); + } + + public function testOwnerId() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => 1))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(1, $task['id']); + $this->assertEquals(1, $task['owner_id']); + } + + public function testCategoryId() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'category_id' => 1))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(1, $task['id']); + $this->assertEquals(1, $task['category_id']); + } + + public function testCreatorId() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'creator_id' => 1))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(1, $task['id']); + $this->assertEquals(1, $task['creator_id']); + } + + public function testColumnId() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(1, $task['id']); + $this->assertEquals(2, $task['column_id']); + $this->assertEquals(1, $task['position']); + } + + public function testPosition() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(1, $task['id']); + $this->assertEquals(2, $task['column_id']); + $this->assertEquals(1, $task['position']); + + $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2))); + + $task = $tf->getById(2); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(2, $task['id']); + $this->assertEquals(2, $task['column_id']); + $this->assertEquals(2, $task['position']); + } + + public function testDescription() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'description' => 'test'))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(1, $task['id']); + $this->assertEquals('test', $task['description']); + } + + public function testReference() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'reference' => 'test'))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(1, $task['id']); + $this->assertEquals('test', $task['reference']); + } + + public function testDateDue() + { + $date = '2014-11-23'; + $timestamp = strtotime('+2days'); + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_due' => $date))); + $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_due' => $timestamp))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(1, $task['id']); + $this->assertEquals($date, date('Y-m-d', $task['date_due'])); + + $task = $tf->getById(2); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(2, $task['id']); + $this->assertEquals($timestamp, $task['date_due']); + } + + public function testDateStarted() + { + $date = '2014-11-23'; + $timestamp = strtotime('+2days'); + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => $date))); + $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => $timestamp))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(1, $task['id']); + $this->assertEquals($date, date('Y-m-d', $task['date_started'])); + + $task = $tf->getById(2); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(2, $task['id']); + $this->assertEquals($timestamp, $task['date_started']); + } + + public function testTime() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => 1.5, 'time_spent' => 2.3))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(1, $task['id']); + $this->assertEquals(1.5, $task['time_estimated']); + $this->assertEquals(2.3, $task['time_spent']); + } + + public function testStripColumn() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'another_task' => '1'))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + } + + public function testScore() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'score' => '3'))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + $this->assertEquals(3, $task['score']); + } +} |