public function testPutItem() { $instance = new CategoryHandler(); $mockItem = m::mock('Xpressengine\\Category\\Models\\CategoryItem'); $mockItem->shouldReceive('isDirty')->once()->with('parentId')->andReturn(true); $mockItem->shouldReceive('getParentIdName')->andReturn('parentId'); $mockItem->shouldReceive('getOriginal')->with('parentId')->andReturn(1); $mockItem->shouldReceive('setAttribute')->with('parentId', 1); $mockItem->shouldReceive('save')->andReturnNull(); $item = $instance->putItem($mockItem); $this->assertInstanceOf('Xpressengine\\Category\\Models\\CategoryItem', $item); }
public function updateItem(CategoryHandler $handler, $categoryId) { $id = Input::get('id'); $inputs = Input::except(['id', '_token']); if ($id === null || !($item = $handler->getItem($id))) { throw new InvalidArgumentHttpException(); } foreach ($inputs as $key => $val) { $item->{$key} = $val; } $item = $handler->putItem($item); return Presenter::makeApi($item->toArray()); }
public function testPutItem() { list($repo, $itemRepo) = $this->getMocks(); $instance = new CategoryHandler($repo, $itemRepo); $mockItemEntity = m::mock('Xpressengine\\Category\\CategoryItemEntity'); $itemRepo->shouldReceive('update')->once()->with($mockItemEntity)->andReturn($mockItemEntity); $item = $instance->putItem($mockItemEntity); $this->assertInstanceOf('Xpressengine\\Category\\CategoryItemEntity', $item); }