removeItem() 공개 메소드

Remove single item or all descendant
public removeItem ( CategoryItem $item, boolean $force = true ) : boolean
$item Xpressengine\Category\Models\CategoryItem item object
$force boolean if true then remove all descendant
리턴 boolean
 public function destroyItem(CategoryHandler $handler, $categoryId)
 {
     $id = Input::get('id');
     if ($id === null || !($item = $handler->getItem($id))) {
         throw new InvalidArgumentHttpException();
     }
     DB::beginTransaction();
     try {
         $handler->removeItem($item);
     } catch (Exception $e) {
         DB::rollBack();
         throw $e;
     }
     DB::commit();
 }
예제 #2
0
 public function testRemoveItem()
 {
     list($repo, $itemRepo) = $this->getMocks();
     $instance = new CategoryHandler($repo, $itemRepo);
     $mockEntity = m::mock('Xpressengine\\Category\\CategoryEntity');
     $mockItemEntity = m::mock('Xpressengine\\Category\\CategoryItemEntity');
     $mockItemEntity->categoryId = 1;
     $itemRepo->shouldReceive('fetchDesc')->once()->with($mockItemEntity, 0, false)->andReturn([$mockItemEntity]);
     $itemRepo->shouldReceive('delete')->once()->with($mockItemEntity)->andReturnNull();
     $itemRepo->shouldReceive('removeHierarchy')->once()->with($mockItemEntity)->andReturnNull();
     $repo->shouldReceive('find')->once()->with(1)->andReturn($mockEntity);
     $repo->shouldReceive('decrement')->once()->with($mockEntity, 1);
     $instance->removeItem($mockItemEntity);
 }
 public function testRemoveItemForceFalse()
 {
     $instance = new CategoryHandler();
     $mockItem = m::mock('Xpressengine\\Category\\Models\\CategoryItem');
     $mockItem->shouldReceive('getKey')->andReturn(1);
     $mockItem->shouldReceive('getParent')->andReturnNull();
     $mockDesc1 = m::mock('Xpressengine\\Category\\Models\\CategoryItem')->shouldAllowMockingProtectedMethods();
     $mockDesc1->shouldReceive('getDescendantName')->andReturn('descendant');
     $mockDesc1->shouldReceive('getAncestorName')->andReturn('ancestor');
     $mockDesc1->shouldReceive('getDepthName')->andReturn('depth');
     $mockDesc1->shouldReceive('getParentIdName')->andReturn('parentId');
     $mockDesc1->shouldReceive('getKey')->andReturn(2);
     $mockDesc1->shouldReceive('descendants')->andReturnSelf();
     $mockDesc1->shouldReceive('newPivotStatement')->andReturnSelf();
     $mockDesc1->shouldReceive('where')->once()->with('descendant', 2)->andReturnSelf();
     $mockDesc1->shouldReceive('where')->once()->with('ancestor', '!=', 1)->andReturnSelf();
     $mockDesc1->shouldReceive('where')->once()->with('depth', '>', 0)->andReturnSelf();
     $mockDesc1->shouldReceive('decrement')->once()->with('depth')->andReturnNull();
     $mockDesc1->shouldReceive('save')->once()->andReturnNull();
     $mockDesc1->shouldReceive('setAttribute');
     $mockItem->shouldReceive('getAttribute')->with('descendants')->andReturn([$mockDesc1]);
     $mockItem->shouldReceive('delete')->andReturn(true);
     $mockModel = m::mock('Xpressengine\\Category\\Models\\Category')->shouldAllowMockingProtectedMethods();
     $mockModel->shouldReceive('decrement')->once()->with('count', 1)->andReturnNull();
     $mockItem->shouldReceive('getAttribute')->with('category')->andReturn($mockModel);
     $instance->removeItem($mockItem, false);
 }