Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function tree($rootCategoryId = null, $depth = null)
 {
     $category = null;
     if (!is_null($rootCategoryId)) {
         /** @var \Magento\Catalog\Model\Category $category */
         $category = $this->categoryFactory->create()->load($rootCategoryId);
         if (!$category->getId()) {
             throw new \Magento\Framework\Exception\NoSuchEntityException('Root Category does not exist');
         }
     }
     $result = $this->categoryTree->getTree($this->categoryTree->getRootNode($category), $depth);
     return $result;
 }
Пример #2
0
 public function testGetRootNode()
 {
     $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $store->expects($this->once())->method('getRootCategoryId')->will($this->returnValue(2));
     $store->expects($this->once())->method('getId')->will($this->returnValue(1));
     $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($store));
     $this->categoryCollection->expects($this->any())->method('addAttributeToSelect')->will($this->returnSelf());
     $this->categoryCollection->expects($this->once())->method('setProductStoreId')->will($this->returnSelf());
     $this->categoryCollection->expects($this->once())->method('setLoadProductCount')->will($this->returnSelf());
     $this->categoryCollection->expects($this->once())->method('setStoreId')->will($this->returnSelf());
     $node = $this->getMockBuilder('Magento\\Catalog\\Model\\Resource\\Category\\Tree')->disableOriginalConstructor()->getMock();
     $node->expects($this->once())->method('addCollectionData')->with($this->equalTo($this->categoryCollection));
     $node->expects($this->once())->method('getNodeById')->with($this->equalTo(2));
     $this->categoryTreeMock->expects($this->once())->method('load')->with($this->equalTo(null))->will($this->returnValue($node));
     $this->tree->getRootNode();
 }