/** * generateNewItemBreadCrumbs * * @param MenuEntity $menu MenuEntity * @param string $parentItemId parent item's id * @param string $newItemId new item's id * * @return array */ protected function generateNewItemBreadCrumbs(MenuEntity $menu, $parentItemId, $newItemId) { if ($parentItemId === $menu->id) { return [$parentItemId, $newItemId]; } $parentItem = $menu->getItem($parentItemId); $breadCrumbs = $parentItem->getBreadCrumbs(); array_push($breadCrumbs, $newItemId); return $breadCrumbs; }
/** * testRemoveMenuFail * * @return void * @throws \Exception */ public function testRemoveMenuFail() { $this->setExpectedException('\\Exception'); $menuRepo = $this->menuRepository; $typeHandler = $this->typeHandler; $routeHandler = $this->routeHandler; $cacheHandler = $this->cacheHandler; $menuHandler = new MenuAlterHandler($menuRepo, $typeHandler, $routeHandler, $cacheHandler); $menu = new MenuEntity(['id' => 'testMenu', 'title' => 'testTitle', 'description' => 'testDescription'], new TreeCollection([new MenuItem(['id' => 'testMenu'])])); $menuItem = new MenuItem(['id' => 'qna', 'parentId' => 'main', 'ordering' => 1, 'activated' => 1, 'type' => 'pluginA@board', 'title' => 'Q & A', 'description' => '질답 게시판입니다.', 'url' => 'qna']); $menu->addItem($menuItem); $menuRepo->shouldReceive('findMenu')->with('basic')->andReturn($menu); $menuRepo->shouldReceive('deleteMenu')->andReturn(); $menuHandler->removeMenu($menu); }
/** * Create New Menu * * @param MenuEntity $menu new menu object to create * * @return MenuEntity */ public function insertMenu(MenuEntity $menu) { $cnt = 0; $result = false; while (!$result && $cnt++ < $this->DUPLICATE_RETRY_CNT) { $menu->id = $this->generateNewId(); try { $result = $this->conn->table($this->treeTable)->insert($menu->getAttributes()); } catch (QueryException $e) { $sqlState = $e->errorInfo[0]; if ($sqlState === "23000") { $result = false; } else { throw $e; } } } if ($result) { return $menu; } throw new CanNotCreateMenuException(); }
/** * testMenuAddItem * * @return void */ public function testMenuAddItem() { $treeCollection = $this->getTreeCollection(); $menu = new MenuEntity(['id' => 'main', 'title' => '기본메뉴', 'description' => '기본메뉴입니다.'], $treeCollection); $menuItem = new MenuItem(['id' => 'qna', 'parentId' => 'main', 'ordering' => 1, 'activated' => 1, 'type' => 'pluginA@board', 'title' => 'Q & A', 'description' => '질답 게시판입니다.', 'url' => 'qna']); $menu->addItem($menuItem); $foundItem = $menu->getItem('qna'); $this->assertEquals('qna', $foundItem->id); $this->assertEquals('main', $foundItem->parentId); $this->assertEquals(1, $foundItem->ordering); $this->assertEquals(true, $foundItem->activated); $this->assertEquals('pluginA@board', $foundItem->type); $this->assertEquals('Q & A', $foundItem->title); $this->assertEquals('질답 게시판입니다.', $foundItem->description); $this->assertEquals('qna', $foundItem->url); }
/** * forgetMenuMap * * @param MenuEntity $menu to forget keys menu map menu object * * @return void */ public function forgetMenuMap(MenuEntity $menu) { $itemKeys = array_keys($menu->getRawItems()); if ($this->cache->has($this->menuMapKey)) { /** * @var $menuMap array */ $menuMap = $this->cache->get($this->menuMapKey); $menuMap = array_except($menuMap, $itemKeys); } else { $menuMap = []; } $this->cache->forever($this->menuMapKey, $menuMap); }