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 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)); }
list($valid, ) = $user->validateModification($values); return $valid && $user->update($values); }); $server->register('removeUser', function ($user_id) use($user) { return $user->remove($user_id); }); /** * Category procedures */ $server->register('createCategory', function ($project_id, $name) use($category) { $values = array('project_id' => $project_id, 'name' => $name); list($valid, ) = $category->validateCreation($values); return $valid && $category->create($values); }); $server->register('getCategory', function ($category_id) use($category) { return $category->getById($category_id); }); $server->register('getAllCategories', function ($project_id) use($category) { return $category->getAll($project_id); }); $server->register('updateCategory', function ($id, $name) use($category) { $values = array('id' => $id, 'name' => $name); list($valid, ) = $category->validateModification($values); return $valid && $category->update($values); }); $server->register('removeCategory', function ($category_id) use($category) { return $category->remove($category_id); }); /** * Comments procedures */