public function testDelete() { list($conn, $query) = $this->getMocks(); $instance = new CategoryItemRepository($conn); $mockItemEntity = m::mock('Xpressengine\\Category\\CategoryItemEntity'); $mockItemEntity->id = 2; $conn->shouldReceive('table')->andReturn($query); $query->shouldReceive('where')->once()->with('id', 2)->andReturnSelf(); $query->shouldReceive('delete')->once()->andReturn(1); $instance->delete($mockItemEntity); }
/** * Remove single item or all descendant * * @param CategoryItemEntity $item item object * @param bool $batch if true then remove all descendant * @return void */ public function removeItem(CategoryItemEntity $item, $batch = true) { $parent = $children = null; if ($batch === true) { $items = $this->itemRepo->fetchDesc($item, 0, false); } else { $items = [$item]; $parent = $this->parent($item); $children = $this->children($item); } $category = $this->get($item->categoryId); foreach ($items as $item) { $this->decrement($category); $this->itemRepo->delete($item); $this->itemRepo->removeHierarchy($item); } if ($parent && $children) { foreach ($children as $child) { $this->itemRepo->insertHierarchy($child, $parent); } } }