/** * Return One Menu by Menu Id * * @param string $menuId menu Id to find one menu * * @return MenuEntity */ public function getMenu($menuId) { if ($this->cache->isExistCachedMenu($menuId)) { return $this->cache->getCachedMenu($menuId); } else { $menu = $this->menuRepository->findMenu($menuId); $this->applyMenuPermission($menu); $this->cache->setCachedMenu($menu); return $menu; } }
/** * Delete Menu 테스트 * * @return void */ public function testDeleteMenu() { $conn = $this->getConnectionMock(); $keygen = $this->getKeygenMock(); $repoInstance = new DBMenuRepository($conn, $keygen); $menuTableQuery = $this->getQueryBuilderMock(); $itemTableQuery = $this->getQueryBuilderMock(); $nodeTableQuery = $this->getQueryBuilderMock(); $treePathQuery = $this->getQueryBuilderMock(); $conn->shouldReceive('table')->with(self::MENU_TABLE)->andReturn($menuTableQuery); $menuTableQuery->shouldReceive('where')->withAnyArgs()->andReturn($menuTableQuery); $menuTableQuery->shouldReceive('first')->withAnyArgs()->andReturn(['id' => 'main', 'title' => '기본메뉴', 'description' => '기본메뉴입니다.']); $conn->shouldReceive('table')->with(self::MENU_ITEM_TABLE . ' as t')->andReturn($nodeTableQuery); $nodeTableQuery->shouldReceive('selectRaw')->withAnyArgs()->andReturn($nodeTableQuery); $nodeTableQuery->shouldReceive('join')->withAnyArgs()->andReturn($nodeTableQuery); $nodeTableQuery->shouldReceive('where')->withAnyArgs()->andReturn($nodeTableQuery); $nodeTableQuery->shouldReceive('where')->withAnyArgs()->andReturn($nodeTableQuery); $nodeTableQuery->shouldReceive('groupBy')->withAnyArgs()->andReturn($nodeTableQuery); $nodeTableQuery->shouldReceive('orderBy')->withAnyArgs()->andReturn($nodeTableQuery); $nodeTableQuery->shouldReceive('get')->withAnyArgs()->andReturn(new Collection([0 => ["id" => "aboutUs", "menuId" => "main", "parentId" => "main", "title" => " 소개", "url" => "aboutUs", "description" => "ddd", "target" => "_self", "type" => "pluginB@page", "ordering" => 0, "activated" => 1, "options" => "", "depth" => 1, "breadcrumbs" => "main,aboutUs"], 1 => ["id" => "freeboard", "menuId" => "main", "parentId" => "main", "title" => "자유게시판", "url" => "freeboard", "description" => "", "target" => "_self", "type" => "pluginA@board", "ordering" => 0, "activated" => 1, "options" => "", "depth" => 1, "breadcrumbs" => "main,freeboard"], 2 => ["id" => "test", "menuId" => "main", "parentId" => "freeboard", "title" => "test", "url" => "test", "description" => "test", "target" => "_self", "type" => "pluginB@widgetPage", "ordering" => 0, "activated" => 1, "options" => "", "depth" => 2, "breadcrumbs" => "main,freeboard,test"], 3 => ["id" => "notice", "menuId" => "main", "parentId" => "main", "title" => "공지 게시판", "url" => "notice", "description" => "공지사항 게시판입니다.", "target" => "_self", "type" => "pluginA@board", "ordering" => 1, "activated" => 1, "options" => "", "depth" => 1, "breadcrumbs" => "main,notice"]])); $menuInstance = $repoInstance->findMenu('main'); $conn->shouldReceive('beginTransaction')->andReturn(true); $conn->shouldReceive('rollBack')->andReturn(true); $conn->shouldReceive('commit')->andReturn(true); $conn->shouldReceive('table')->with(self::MENU_TREE_PATH_TABLE)->andReturn($treePathQuery); $treePathQuery->shouldReceive('where')->andReturn($treePathQuery); $treePathQuery->shouldReceive('delete')->andReturn(true); $conn->shouldReceive('table')->with(self::MENU_ITEM_TABLE)->andReturn($itemTableQuery); $itemTableQuery->shouldReceive('whereIn')->andReturn($itemTableQuery); $itemTableQuery->shouldReceive('delete')->andReturn(true); $nodeTableQuery->shouldReceive('where')->andReturn($nodeTableQuery); $nodeTableQuery->shouldReceive('delete')->andReturn(true); $menuTableQuery->shouldReceive('where')->andReturnNull($menuTableQuery); $menuTableQuery->shouldReceive('delete')->andReturnNull(true); $repoInstance->deleteMenu($menuInstance); }