/**
  * testMoveItemPermission
  *
  * @return void
  */
 public function testMoveItemPermission()
 {
     $originItem = $this->getSampleMenuItem();
     $movedItem = new MenuItem(['id' => 'testboard', 'parentId' => 'freeboard', 'ordering' => 1, 'activated' => 1, 'type' => 'pluginA@board', 'title' => 'Test 게시판', 'description' => '테스트 게시판입니다.', 'url' => 'testboard']);
     $movedItem->setBreadCrumbs(['basic', 'board', 'freeboard']);
     $registered = m::mock('Xpressengine\\Permission\\Registered');
     $permissionFactory = $this->permissionFactory;
     $permissionFactory->shouldReceive('findRegistered')->andReturn($registered);
     $permissionFactory->shouldReceive('move')->andReturn();
     $permissionHandler = new MenuPermissionHandler($permissionFactory, $this->groupRepoMock, $this->memberRepoMock);
     $permissionHandler->moveItemPermission($originItem, $movedItem);
 }
 /**
  * testJsonSerialize
  *
  * @return void
  */
 public function testJsonSerialize()
 {
     $menuItem = new MenuItem(['id' => 'freeboard', 'parentId' => 'main', 'ordering' => 1, 'activated' => 1, 'type' => 'pluginA@board', 'title' => '자유게시판', 'description' => '자유게시판 게시판입니다.', 'url' => 'freeboard']);
     $childItem = new MenuItem(['id' => 'qna', 'parentId' => 'freeboard', 'ordering' => 1, 'activated' => 1, 'type' => 'pluginA@board', 'title' => 'Q & A', 'description' => '질답 게시판입니다.', 'url' => 'qna']);
     $menuItem->addChild($childItem);
     $menuItemJson = json_encode($menuItem);
     $this->assertEquals('{"id":"freeboard","parentId":"main","ordering":1,"activated":1,"type":"pluginA@board","title":"\\uc790\\uc720\\uac8c\\uc2dc\\ud310","description":"\\uc790\\uc720\\uac8c\\uc2dc\\ud310 \\uac8c\\uc2dc\\ud310\\uc785\\ub2c8\\ub2e4.","url":"freeboard","items":{"qna":{"id":"qna","parentId":"freeboard","ordering":1,"activated":1,"type":"pluginA@board","title":"Q & A","description":"\\uc9c8\\ub2f5 \\uac8c\\uc2dc\\ud310\\uc785\\ub2c8\\ub2e4.","url":"qna","items":[]}}}', $menuItemJson);
 }
Esempio n. 3
0
 /**
  * SettingsMenu constructor.
  *
  * @param array $attributes 메뉴정보
  */
 public function __construct(array $attributes = [])
 {
     $this->resolveParentId($attributes);
     parent::__construct($attributes);
 }
 /**
  * Delete Menu Item at Menu
  *
  * @param MenuItem $item 삭제하려는 MenuItem
  *
  * @return int
  * @throws CanNotDeleteMenuItemHaveChildException
  */
 public function removeItem(MenuItem $item)
 {
     if ($item->hasChild()) {
         throw new CanNotDeleteMenuItemHaveChildException();
     }
     $menuType = $item->type;
     $menuTypeObj = $this->typeHandler->getModuleObject($menuType);
     $affectedRow = $this->menuRepository->deleteItem($item);
     $this->menuRepository->removeHierarchy($item);
     $menuTypeObj->deleteMenu($item->id);
     if ($menuTypeObj::isRouteAble()) {
         $instanceRoute = $this->routeHandler->getByInstanceId($item->id);
         $this->routeHandler->remove($instanceRoute);
     }
     $this->cache->deleteCachedMenu($item->menuId);
     return $affectedRow;
 }
 /**
  * moveItemConfig
  *
  * @param MenuItem $fromItem  item of before moving
  * @param MenuItem $movedItem item of after moving
  *
  * @return void
  */
 public function moveItemPermission(MenuItem $fromItem, MenuItem $movedItem)
 {
     $registered = $this->permission->findRegistered($this->permissionType, $fromItem->getBreadCrumbsKeyString());
     $this->permission->move($registered, $movedItem->getBreadCrumbsKeyString());
 }
 /**
  * testMoveItemConfig
  *
  * @return void
  */
 public function testMoveItemConfig()
 {
     // MenuItem $item, MenuItem $movedItem
     $configManager = $this->configManager;
     $themeHandler = $this->themeHandler;
     $dummyConfigEntity = m::mock('Xpressengine\\Config\\ConfigEntity');
     $configManager->shouldReceive('get')->andReturn($dummyConfigEntity);
     $configManager->shouldReceive('move')->andReturn($dummyConfigEntity);
     $dummyItem = new MenuItem(['id' => 'testMenu']);
     $dummyItem->setBreadCrumbs(['basic', 'board']);
     $dummyMovedItem = new MenuItem(['id' => 'movedTestMenu']);
     $dummyMovedItem->setBreadCrumbs(['basic', 'notice']);
     $menuConfigHandler = new MenuConfigHandler($configManager, $themeHandler);
     $menuConfigHandler->moveItemConfig($dummyItem, $dummyMovedItem);
 }
 /**
  * testRemoveItemFail
  *
  * @return void
  */
 public function testRemoveItemFail()
 {
     $this->setExpectedException('Xpressengine\\Menu\\Exceptions\\CanNotDeleteMenuItemHaveChildException');
     $menuRepo = $this->menuRepository;
     $typeHandler = $this->typeHandler;
     $routeHandler = $this->routeHandler;
     $cacheHandler = $this->cacheHandler;
     $instanceRouteMock = m::mock('Xpressengine\\Routing\\InstanceRoute');
     $instanceRouteMock->shouldReceive('setUrl')->andReturn();
     $menuRepo->shouldReceive('countItem')->andReturn(1);
     $menuRepo->shouldReceive('deleteItem')->andReturn();
     $menuRepo->shouldReceive('removeHierarchy')->andReturn();
     $routeHandler->shouldReceive('remove')->andReturn();
     $menuHandler = new MenuAlterHandler($menuRepo, $typeHandler, $routeHandler, $cacheHandler);
     $dummyMenuType = m::mock('alias:Theme', 'Xpressengine\\Menu\\MenuType\\MenuTypeInterface', ['isRouteAble' => true]);
     $testItem = new MenuItem(['id' => 'testItem', 'type' => 'testType']);
     $testChildItem = new MenuItem(['id' => 'testChild', 'parentId' => 'testItem']);
     $testItem->addChild($testChildItem);
     $dummyMenuType->shouldReceive('deleteMenu')->andReturn();
     $typeHandler->shouldReceive('getModuleObject')->andReturn($dummyMenuType);
     $typeHandler->shouldReceive('updateMenu')->andReturn(0);
     $menuHandler->removeItem($testItem);
 }
 /**
  * getTreeCollection
  *
  * @return TreeCollection
  */
 private function getTreeCollection()
 {
     $treeRows = [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"]];
     $nodes = [];
     foreach ($treeRows as $row) {
         $node = new MenuItem(array_diff_key($row, array_flip(['depth', 'breadcrumbs'])));
         $node->setdepth($row['depth']);
         $node->setBreadcrumbs(explode(',', $row['breadcrumbs']));
         $nodes[$node->id] = $node;
     }
     return new TreeCollection($nodes);
 }
 /**
  * Create New Item on Menu
  *
  * @param MenuItem $item new menuItem object to add at menu
  *
  * @return MenuItem
  * @throws Exception
  */
 public function insertItem(MenuItem $item)
 {
     $cnt = 0;
     $result = false;
     while (!$result && $cnt++ < $this->DUPLICATE_RETRY_CNT) {
         $item->id = $this->generateNewId();
         try {
             $result = $this->conn->table($this->nodeTable)->insert($item->getAttributes());
         } catch (QueryException $e) {
             $sqlState = $e->errorInfo[0];
             if ($sqlState === "23000") {
                 $result = false;
             } else {
                 throw $e;
             }
         }
     }
     if ($result) {
         return $item;
     }
     throw new CanNotCreateItemException();
 }
 /**
  * moveItemConfig
  *
  * @param MenuItem $beforeItem to change theme value for before item moving
  * @param MenuItem $movedItem  to change theme value for after item moving
  *
  * @return void
  * @throws InvalidArgumentException
  */
 public function moveItemConfig(MenuItem $beforeItem, MenuItem $movedItem)
 {
     $configEntity = $this->configManager->get($this->menuKeyString($beforeItem->getBreadCrumbsKeyString()));
     $this->configManager->move($configEntity, $this->menuKeyString($movedItem->getBreadCrumbsKeyString(true)));
 }