Example #1
0
 public function testGetTreeHasLevelField()
 {
     $rootId = \Magento\Catalog\Model\Category::TREE_ROOT_ID;
     $storeGroups = [];
     $storeId = 1;
     $rootLevel = 2;
     $level = 3;
     $this->collection->expects($this->any())->method('addAttributeToSelect')->willReturnMap([['url_key', false, $this->collection], ['is_anchor', false, $this->collection]]);
     $this->childNode->expects($this->atLeastOnce())->method('getLevel')->willReturn($level);
     $this->rootNode->expects($this->atLeastOnce())->method('getLevel')->willReturn($rootLevel);
     $this->rootNode->expects($this->once())->method('hasChildren')->willReturn(true);
     $this->rootNode->expects($this->once())->method('getChildren')->willReturn([$this->childNode]);
     $this->categoryTree->expects($this->once())->method('load')->with(null, 3)->willReturnSelf();
     $this->categoryTree->expects($this->atLeastOnce())->method('addCollectionData')->with($this->collection)->willReturnSelf();
     $this->categoryTree->expects($this->once())->method('getNodeById')->with($rootId)->willReturn($this->rootNode);
     $this->store->expects($this->atLeastOnce())->method('getId')->willReturn($storeId);
     $this->storeManager->expects($this->once())->method('getGroups')->willReturn($storeGroups);
     $this->storeManager->expects($this->atLeastOnce())->method('getStore')->willReturn($this->store);
     $this->context->expects($this->once())->method('getStoreManager')->willReturn($this->storeManager);
     $this->context->expects($this->once())->method('getRequest')->willReturn($this->request);
     $this->context->expects($this->once())->method('getEscaper')->willReturn($this->escaper);
     $this->context->expects($this->once())->method('getEventManager')->willReturn($this->eventManager);
     /** @var \Magento\Widget\Block\Adminhtml\Widget\Catalog\Category\Chooser $chooser */
     $chooser = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject('Magento\\Widget\\Block\\Adminhtml\\Widget\\Catalog\\Category\\Chooser', ['categoryTree' => $this->categoryTree, 'context' => $this->context]);
     $chooser->setData('category_collection', $this->collection);
     $result = $chooser->getTree();
     $this->assertEquals($level, $result[0]['level']);
 }
Example #2
0
 /**
  * @param \Magento\Catalog\Model\Category $category
  * @return Node
  */
 protected function getNode(\Magento\Catalog\Model\Category $category)
 {
     $nodeId = $category->getId();
     $node = $this->categoryTree->loadNode($nodeId);
     $node->loadChildren();
     $this->prepareCollection();
     $this->categoryTree->addCollectionData($this->categoryCollection);
     return $node;
 }
 /**
  * @param mixed $parentNodeCategory
  * @param int $recursionLevel
  * @return Node
  */
 public function getNode($parentNodeCategory, $recursionLevel = 2)
 {
     $nodeId = $parentNodeCategory->getId();
     $node = $this->_categoryTree->loadNode($nodeId);
     $node->loadChildren($recursionLevel);
     if ($node && $nodeId != \Magento\Catalog\Model\Category::TREE_ROOT_ID) {
         $node->setIsVisible(true);
     } elseif ($node && $node->getId() == \Magento\Catalog\Model\Category::TREE_ROOT_ID) {
         $node->setName(__('Root'));
     }
     $this->_categoryTree->addCollectionData($this->getCategoryCollection());
     return $node;
 }
 public function testSetCollection()
 {
     $collection = $this->getCollectionMock();
     $this->_model->setCollection($collection);
     $this->assertSame($collection, $this->_model->getCollection());
 }