Exemplo n.º 1
0
 public function setUp()
 {
     $isCurrentItem = $this->getName() == 'testGetHtmlWithSelectedCategory' ? true : false;
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->context = $objectManager->getObject('Magento\\Framework\\View\\Element\\Template\\Context');
     $this->nodeFactory = $this->getMock('Magento\\Framework\\Data\\Tree\\NodeFactory', [], [], '', false);
     $this->treeFactory = $this->getMock('Magento\\Framework\\Data\\TreeFactory', [], [], '', false);
     $tree = $this->getMock('Magento\\Framework\\Data\\Tree', [], [], '', false);
     $container = $this->getMock('Magento\\Catalog\\Model\\Resource\\Category\\Tree', [], [], '', false);
     $children = $this->getMock('Magento\\Framework\\Data\\Tree\\Node\\Collection', ['count'], ['container' => $container]);
     for ($i = 0; $i < 10; $i++) {
         $id = "category-node-{$i}";
         $categoryNode = $this->getMock('Magento\\Framework\\Data\\Tree\\Node', ['getId', 'hasChildren'], [], '', false);
         $categoryNode->expects($this->once())->method('getId')->willReturn($id);
         $categoryNode->expects($this->atLeastOnce())->method('hasChildren')->willReturn(false);
         $categoryNode->setData(['name' => "Category {$i}", 'id' => $id, 'url' => "http://magento2/category-{$i}.html", 'is_active' => $i == 0 ? $isCurrentItem : false, 'is_current_item' => $i == 0 ? $isCurrentItem : false]);
         $children->add($categoryNode);
     }
     $children->expects($this->once())->method('count')->willReturn(10);
     $node = $this->getMock('Magento\\Framework\\Data\\Tree\\Node', ['getChildren'], [], '', false);
     $node->expects($this->once())->method('getChildren')->willReturn($children);
     $node->expects($this->any())->method('__call')->with('getLevel', [])->willReturn(null);
     $this->nodeFactory->expects($this->once())->method('create')->willReturn($node);
     $this->treeFactory->expects($this->once())->method('create')->willReturn($tree);
 }
Exemplo n.º 2
0
 /**
  * @param $isCurrentItem
  * @return void
  */
 private function buildTree($isCurrentItem)
 {
     $this->nodeFactory = $this->getMock('Magento\\Framework\\Data\\Tree\\NodeFactory', [], [], '', false);
     $this->treeFactory = $this->getMock('Magento\\Framework\\Data\\TreeFactory', [], [], '', false);
     $tree = $this->getMock('Magento\\Framework\\Data\\Tree', [], [], '', false);
     $container = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Category\\Tree', [], [], '', false);
     $children = $this->getMock('Magento\\Framework\\Data\\Tree\\Node\\Collection', ['count'], ['container' => $container]);
     for ($i = 0; $i < 10; $i++) {
         $id = "category-node-{$i}";
         $categoryNode = $this->getMock('Magento\\Framework\\Data\\Tree\\Node', ['getId', 'hasChildren'], [], '', false);
         $categoryNode->expects($this->once())->method('getId')->willReturn($id);
         $categoryNode->expects($this->atLeastOnce())->method('hasChildren')->willReturn(false);
         $categoryNode->setData(['name' => "Category {$i}", 'id' => $id, 'url' => "http://magento2/category-{$i}.html", 'is_active' => $i == 0 ? $isCurrentItem : false, 'is_current_item' => $i == 0 ? $isCurrentItem : false]);
         $children->add($categoryNode);
     }
     $children->expects($this->once())->method('count')->willReturn(10);
     $node = $this->getMock('Magento\\Framework\\Data\\Tree\\Node', ['getChildren'], [], '', false);
     $node->expects($this->once())->method('getChildren')->willReturn($children);
     $node->expects($this->any())->method('__call')->with('getLevel', [])->willReturn(null);
     $this->nodeFactory->expects($this->once())->method('create')->willReturn($node);
     $this->treeFactory->expects($this->once())->method('create')->willReturn($tree);
 }
Exemplo n.º 3
0
 /**
  * @param Template\Context $context
  * @param NodeFactory $nodeFactory
  * @param TreeFactory $treeFactory
  * @param array $data
  */
 public function __construct(Template\Context $context, NodeFactory $nodeFactory, TreeFactory $treeFactory, array $data = [])
 {
     parent::__construct($context, $data);
     $this->_menu = $nodeFactory->create(['data' => [], 'idField' => 'root', 'tree' => $treeFactory->create()]);
 }