summaryrefslogtreecommitdiff
path: root/tests/units/CategoryTest.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-09-11 18:28:17 +0200
committerFrédéric Guillot <fred@kanboard.net>2014-09-11 18:28:17 +0200
commit61927232aeeea277344262aa5c92cd9fbedce854 (patch)
treea79bc0e22281535d0b95390407a1402c742b56c9 /tests/units/CategoryTest.php
parentd9850ae66ac7c6545633b3cfa0fe1b811b27bc41 (diff)
Improve API calls for categories
Diffstat (limited to 'tests/units/CategoryTest.php')
-rw-r--r--tests/units/CategoryTest.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/units/CategoryTest.php b/tests/units/CategoryTest.php
new file mode 100644
index 00000000..201fa589
--- /dev/null
+++ b/tests/units/CategoryTest.php
@@ -0,0 +1,57 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\Task;
+use Model\Project;
+use Model\Category;
+use Model\User;
+
+class CategoryTest extends Base
+{
+ public function testCreation()
+ {
+ $t = new Task($this->registry);
+ $p = new Project($this->registry);
+ $c = new Category($this->registry);
+
+ $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, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2)));
+
+ $task = $t->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']);
+ }
+
+ public function testRemove()
+ {
+ $t = new Task($this->registry);
+ $p = new Project($this->registry);
+ $c = new Category($this->registry);
+
+ $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, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2)));
+
+ $task = $t->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 = $t->getById(1);
+ $this->assertTrue(is_array($task));
+ $this->assertEquals(0, $task['category_id']);
+ }
+}