Example #1
0
 /**
  * Add a category item
  *
  * @param CategoryEntity     $category category object
  * @param CategoryItemEntity $item     item object
  * @param CategoryItemEntity $parent   parent item object
  * @return CategoryItemEntity
  */
 public function addItem(CategoryEntity $category, CategoryItemEntity $item, CategoryItemEntity $parent = null)
 {
     $item->categoryId = $category->id;
     $item = $this->itemRepo->insert($item);
     $this->itemRepo->insertHierarchy($item, $parent);
     // set default last
     $this->setOrder($item, $category->count);
     $this->increment($category);
     return $item;
 }
 public function testInsert()
 {
     list($conn, $query) = $this->getMocks();
     $instance = new CategoryItemRepository($conn);
     $mockItemEntity = m::mock('Xpressengine\\Category\\CategoryItemEntity');
     $mockItemEntity->shouldReceive('getAttributes')->andReturn(['categoryId' => 1, 'word' => 'blarblar']);
     $conn->shouldReceive('table')->andReturn($query);
     $query->shouldReceive('insertGetId')->once()->with(m::on(function ($array) {
         return $array['categoryId'] === 1 && $array['word'] === 'blarblar';
     }))->andReturn(2);
     $item = $instance->insert($mockItemEntity);
     $this->assertEquals(2, $item->id);
     $this->assertEquals(1, $item->categoryId);
     $this->assertEquals('blarblar', $item->word);
 }