Example #1
0
 /**
  * Set a target unused category item
  *
  * @param string             $targetId target id
  * @param CategoryItemEntity $item     item object
  * @return void
  */
 public function unused($targetId, CategoryItemEntity $item)
 {
     if ($this->itemRepo->existsUsed($targetId, $item)) {
         $this->itemRepo->deleteUsed($targetId, $item);
         $item->count--;
         $this->itemRepo->update($item);
     }
 }
 public function testExistsUsed()
 {
     list($conn, $query) = $this->getMocks();
     $instance = new CategoryItemRepository($conn);
     $targetId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
     $mockItemEntity = m::mock('Xpressengine\\Category\\CategoryItemEntity');
     $mockItemEntity->id = 2;
     $conn->shouldReceive('table')->andReturn($query);
     $query->shouldReceive('where')->once()->with('targetId', $targetId)->andReturnSelf();
     $query->shouldReceive('where')->once()->with('itemId', 2)->andReturnSelf();
     $query->shouldReceive('exists')->once()->andReturn(true);
     $this->assertTrue($instance->existsUsed($targetId, $mockItemEntity));
 }