summaryrefslogtreecommitdiff
path: root/tests/units/Model/CategoryTest.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-09-05 23:30:56 -0400
committerFrederic Guillot <fred@kanboard.net>2015-09-05 23:30:56 -0400
commit710f2c7bb046b43ec9878ae795a181101f6d7515 (patch)
treeb62723b6b49c3b6bf2b3ca41a772f552464a9031 /tests/units/Model/CategoryTest.php
parent94b38dd94bd819168163003beec8ef693f9d9839 (diff)
Improve unit tests
Diffstat (limited to 'tests/units/Model/CategoryTest.php')
-rw-r--r--tests/units/Model/CategoryTest.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/units/Model/CategoryTest.php b/tests/units/Model/CategoryTest.php
new file mode 100644
index 00000000..0467dda4
--- /dev/null
+++ b/tests/units/Model/CategoryTest.php
@@ -0,0 +1,67 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Model\Task;
+use Model\TaskCreation;
+use Model\TaskFinder;
+use Model\Project;
+use Model\Category;
+use Model\User;
+
+class CategoryTest extends Base
+{
+ public function testCreation()
+ {
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $c = new Category($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $c->create(array('name' => 'Category #1', 'project_id' => 1)));
+ $this->assertEquals(2, $c->create(array('name' => 'Category #2', 'project_id' => 1)));
+ $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2)));
+
+ $task = $tf->getById(1);
+ $this->assertTrue(is_array($task));
+ $this->assertEquals(2, $task['category_id']);
+
+ $category = $c->getById(2);
+ $this->assertTrue(is_array($category));
+ $this->assertEquals(2, $category['id']);
+ $this->assertEquals('Category #2', $category['name']);
+ $this->assertEquals(1, $category['project_id']);
+
+ $this->assertEquals(2, $c->getIdByName(1, 'Category #2'));
+ $this->assertEquals(0, $c->getIdByName(2, 'Category #2'));
+
+ $this->assertEquals('Category #2', $c->getNameById(2));
+ $this->assertEquals('', $c->getNameById(23));
+ }
+
+ public function testRemove()
+ {
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $c = new Category($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $c->create(array('name' => 'Category #1', 'project_id' => 1)));
+ $this->assertEquals(2, $c->create(array('name' => 'Category #2', 'project_id' => 1)));
+ $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2)));
+
+ $task = $tf->getById(1);
+ $this->assertTrue(is_array($task));
+ $this->assertEquals(2, $task['category_id']);
+
+ $this->assertTrue($c->remove(1));
+ $this->assertTrue($c->remove(2));
+
+ // Make sure tasks assigned with that category are reseted
+ $task = $tf->getById(1);
+ $this->assertTrue(is_array($task));
+ $this->assertEquals(0, $task['category_id']);
+ }
+}