public function testCreate() { list($repo, $configs, $modules, $routes) = $this->getMocks(); $instance = new MenuHandler($repo, $configs, $modules, $routes); $mockMenu = m::mock('Xpressengine\\Menu\\Models\\Menu'); $mockMenu->shouldReceive('fill')->once()->with(['title' => 'test title', 'description' => 'test description']); $repo->shouldReceive('createModel')->andReturn($mockMenu); $repo->shouldReceive('insert')->with($mockMenu)->andReturn($mockMenu); $menu = $instance->create(['title' => 'test title', 'description' => 'test description']); }
/** * store * 새로운 메뉴 생성을 처리하는 메소드 * * @param MenuHandler $handler menu handler * * @return mixed * @throws Exception */ public function store(MenuHandler $handler) { $desktopTheme = Input::get('theme_desktop'); $mobileTheme = Input::get('theme_mobile'); $rules = ['menuTitle' => 'required', 'theme_desktop' => 'required', 'theme_mobile' => 'required']; $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { Input::flash(); return Redirect::back()->with('alert', ['type' => 'danger', 'message' => $validator->messages()]); } XeDB::beginTransaction(); try { $menu = $handler->create(['title' => Input::get('menuTitle'), 'description' => Input::get('menuDescription'), 'siteKey' => Input::get('siteKey')]); $handler->setMenuTheme($menu, $desktopTheme, $mobileTheme); $this->permissionRegisterGrant($menu->getKey(), $handler->getDefaultGrant()); } catch (Exception $e) { XeDB::rollback(); Input::flash(); return Redirect::back()->with('alert', ['type' => 'danger', 'message' => $e->getMessage()]); } XeDB::commit(); return Redirect::route('settings.menu.index'); }