public function children(CategoryHandler $handler, $categoryId) { $parentId = Input::get('id'); if ($parentId === null) { $category = $handler->get($categoryId); $children = $handler->progenitors($category); } else { if (!($parent = $handler->getItem($parentId))) { throw new InvalidArgumentHttpException(); } $children = $handler->children($parent); } return Presenter::makeApi($children); }
public function testChildren() { list($repo, $itemRepo) = $this->getMocks(); $instance = new CategoryHandler($repo, $itemRepo); $mockItemEntity = m::mock('Xpressengine\\Category\\CategoryItemEntity'); $mockChild1 = m::mock('Xpressengine\\Category\\CategoryItemEntity'); $mockChild2 = m::mock('Xpressengine\\Category\\CategoryItemEntity'); $itemRepo->shouldReceive('fetchDesc')->once($mockItemEntity, 1)->andReturn([$mockChild1, $mockChild2]); $children = $instance->children($mockItemEntity); $this->assertEquals(2, count($children)); }