From 61927232aeeea277344262aa5c92cd9fbedce854 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Thu, 11 Sep 2014 18:28:17 +0200 Subject: Improve API calls for categories --- tests/functionals/ApiTest.php | 75 +++++++++++++++++++++++++++++++++++++++++++ tests/units/CategoryTest.php | 57 ++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 tests/units/CategoryTest.php (limited to 'tests') diff --git a/tests/functionals/ApiTest.php b/tests/functionals/ApiTest.php index bc0bbe42..1f71020a 100644 --- a/tests/functionals/ApiTest.php +++ b/tests/functionals/ApiTest.php @@ -418,4 +418,79 @@ class Api extends PHPUnit_Framework_TestCase $this->assertEquals(1, $task['position']); $this->assertEquals(3, $task['column_id']); } + + public function testCategoryCreation() + { + $category = array( + 'name' => 'Category', + 'project_id' => 1, + ); + + $this->assertTrue($this->client->execute('createCategory', $category)); + + // Duplicate + + $category = array( + 'name' => 'Category', + 'project_id' => 1, + ); + + $this->assertFalse($this->client->execute('createCategory', $category)); + + // Missing project id + + $category = array( + 'name' => 'Category', + ); + + $this->assertNull($this->client->execute('createCategory', $category)); + } + + public function testCategoryRead() + { + $category = $this->client->getCategory(1); + + $this->assertTrue(is_array($category)); + $this->assertNotEmpty($category); + $this->assertEquals(1, $category['id']); + $this->assertEquals('Category', $category['name']); + $this->assertEquals(1, $category['project_id']); + } + + public function testGetAllCategories() + { + $categories = $this->client->getAllCategories(1); + + $this->assertNotEmpty($categories); + $this->assertNotFalse($categories); + $this->assertTrue(is_array($categories)); + $this->assertEquals(1, count($categories)); + $this->assertEquals(1, $categories[0]['id']); + $this->assertEquals('Category', $categories[0]['name']); + $this->assertEquals(1, $categories[0]['project_id']); + } + + public function testCategoryUpdate() + { + $category = array( + 'id' => 1, + 'name' => 'Renamed category', + ); + + $this->assertTrue($this->client->execute('updateCategory', $category)); + + $category = $this->client->getCategory(1); + $this->assertTrue(is_array($category)); + $this->assertNotEmpty($category); + $this->assertEquals(1, $category['id']); + $this->assertEquals('Renamed category', $category['name']); + $this->assertEquals(1, $category['project_id']); + } + + public function testCategoryRemove() + { + $this->assertTrue($this->client->removeCategory(1)); + $this->assertFalse($this->client->removeCategory(1)); + $this->assertFalse($this->client->removeCategory(1111)); + } } 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 @@ +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']); + } +} -- cgit v1.2.3