public function moveItem(CategoryHandler $handler, $categoryId) { $id = Input::get('id'); $parentId = Input::get('parentId'); $ordering = Input::get('ordering'); if ($id === null || !($item = $handler->getItem($id))) { throw new InvalidArgumentHttpException(); } $parent = empty($parentId) === false ? $handler->getItem($parentId) : null; DB::beginTransaction(); try { $handler->moveTo($item, $parent); $handler->setOrder($item, $ordering); } catch (Exception $e) { DB::rollBack(); throw $e; } DB::commit(); }
public function testSetOrder() { list($repo, $itemRepo) = $this->getMocks(); $instance = new CategoryHandler($repo, $itemRepo); $mockItemEntity = m::mock('Xpressengine\\Category\\CategoryItemEntity'); $mockItemEntity->id = 3; $mockParent = m::mock('Xpressengine\\Category\\CategoryItemEntity'); $mockChild1 = m::mock('Xpressengine\\Category\\CategoryItemEntity'); $mockChild1->id = 1; $mockChild1->ordering = 0; $mockChild2 = m::mock('Xpressengine\\Category\\CategoryItemEntity'); $mockChild2->id = 2; $mockChild1->ordering = 1; $itemRepo->shouldReceive('fetchAsc')->once()->with($mockItemEntity, 1)->andReturn([$mockParent]); $itemRepo->shouldReceive('fetchDesc')->once()->with($mockParent, 1)->andReturn([$mockChild1, $mockChild2]); $itemRepo->shouldReceive('update')->once()->with($mockChild1)->andReturnNull(); $itemRepo->shouldReceive('update')->once()->with($mockItemEntity)->andReturnNull(); $itemRepo->shouldReceive('update')->once()->with($mockChild2)->andReturnNull(); $instance->setOrder($mockItemEntity, 1); }