/**
  * 카테고리 아이템에 속하는 대상 아이디 목록을 반환
  *
  * @param CategoryItemEntity $item item object
  * @return array
  */
 public function getTargetIds(CategoryItemEntity $item)
 {
     $items = $this->itemRepo->fetchDesc($item, 0, false);
     $ids = [];
     foreach ($items as $item) {
         $ids[] = $item->id;
     }
     return $this->itemRepo->fetchTargetIdsByIds($ids);
 }
 public function testHasMany()
 {
     list($conn, $query) = $this->getMocks();
     $instance = new CategoryItemRepository($conn);
     $targetId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
     $mockItemEntity1 = m::mock('Xpressengine\\Category\\CategoryItemEntity');
     $mockItemEntity2 = m::mock('Xpressengine\\Category\\CategoryItemEntity');
     $conn->shouldReceive('table')->andReturn($query);
     $query->shouldReceive('leftJoin')->andReturnSelf();
     $query->shouldReceive('where')->once()->with('used.targetId', $targetId)->andReturnSelf();
     $query->shouldReceive('select')->once()->with(['node.*'])->andReturnSelf();
     $query->shouldReceive('get')->once()->andReturn([$mockItemEntity1, $mockItemEntity2]);
     $items = $instance->hasMany($targetId);
     $this->assertEquals(2, count($items));
 }
 /**
  * Get an item's descendant count
  *
  * @param CategoryItemEntity $top   std item object for counting
  * @param int                $depth search depth value
  * @return int
  */
 public function count(CategoryItemEntity $top, $depth = 0)
 {
     return $this->itemRepo->count($top, $depth);
 }
 public function testFetchTargetIdsByIds()
 {
     list($conn, $query) = $this->getMocks();
     $instance = new CategoryItemRepository($conn);
     $conn->shouldReceive('table')->andReturn($query);
     $query->shouldReceive('whereIn')->once()->with('itemId', [1, 2, 3])->andReturnSelf();
     $query->shouldReceive('get')->once()->andReturn([(object) ['targetId' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxa'], (object) ['targetId' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxb'], (object) ['targetId' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxc'], (object) ['targetId' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxd'], (object) ['targetId' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxe'], (object) ['targetId' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxf']]);
     $targetIds = $instance->fetchTargetIdsByIds([1, 2, 3]);
     $this->assertEquals(['xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxa', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxb', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxc', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxd', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxe', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxf'], $targetIds);
 }