public function testGetMenuCategoryData()
 {
     $category = $this->getMock('Magento\\Catalog\\Model\\Category', ['getId', 'getName'], [], '', false);
     $category->expects($this->once())->method('getId')->willReturn('id');
     $category->expects($this->once())->method('getName')->willReturn('name');
     $this->_catalogCategory->expects($this->once())->method('getCategoryUrl')->willReturn('url');
     $this->assertEquals(['name' => 'name', 'id' => 'category-node-id', 'url' => 'url', 'is_active' => false, 'has_active' => false], $this->_observer->getMenuCategoryData($category));
 }
 protected function _preparationData()
 {
     $this->_childrenCategory = $this->getMock('\\Magento\\Catalog\\Model\\Category', ['getIsActive', '__wakeup'], [], '', false);
     $this->_childrenCategory->expects($this->once())->method('getIsActive')->will($this->returnValue(false));
     $this->_category = $this->getMock('\\Magento\\Catalog\\Model\\Category', ['getIsActive', '__wakeup', 'getName', 'getChildren', 'getUseFlatResource', 'getChildrenNodes'], [], '', false);
     $this->_category->expects($this->once())->method('getIsActive')->will($this->returnValue(true));
     $this->_catalogCategory->expects($this->once())->method('getStoreCategories')->will($this->returnValue([$this->_category]));
     $this->menuCategoryData->expects($this->once())->method('getMenuCategoryData')->with($this->_category);
     $blockMock = $this->_getCleanMock('\\Magento\\Theme\\Block\\Html\\Topmenu');
     $treeMock = $this->_getCleanMock('\\Magento\\Framework\\Data\\Tree');
     $menuMock = $this->getMock('\\Magento\\Framework\\Data\\Tree\\Node', ['getTree', 'addChild'], [], '', false);
     $menuMock->expects($this->once())->method('getTree')->will($this->returnValue($treeMock));
     $eventMock = $this->getMock('\\Magento\\Framework\\Event', ['getBlock'], [], '', false);
     $eventMock->expects($this->once())->method('getBlock')->will($this->returnValue($blockMock));
     $observerMock = $this->getMock('\\Magento\\Framework\\Event\\Observer', ['getEvent', 'getMenu'], [], '', false);
     $observerMock->expects($this->once())->method('getEvent')->will($this->returnValue($eventMock));
     $observerMock->expects($this->once())->method('getMenu')->will($this->returnValue($menuMock));
     return $observerMock;
 }
예제 #3
0
 /**
  * @expectedException \Magento\Framework\Model\Exception
  * @expectedExceptionMessage Invalid category object supplied
  */
 public function testGetUrlPath()
 {
     $urlPathProduct = '/some/url/path';
     $urlPathCategory = '/some/url/path/category';
     $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['getData', '__wakeup'])->getMock();
     $product->expects($this->atLeastOnce())->method('getData')->with('url_path')->will($this->returnValue($urlPathProduct));
     $category = $this->getMockBuilder('Magento\\Catalog\\Model\\Category')->disableOriginalConstructor()->setMethods(['getUrlPath', '__wakeup'])->getMock();
     $category->expects($this->atLeastOnce())->method('getUrlPath')->will($this->returnValue($urlPathCategory));
     $this->catalogCategory->expects($this->atLeastOnce())->method('getCategoryUrlPath')->with($urlPathCategory)->will($this->returnValue($urlPathCategory));
     $this->assertEquals($urlPathProduct, $this->model->getUrlPath($product));
     $this->assertEquals($urlPathCategory . '/' . $urlPathProduct, $this->model->getUrlPath($product, $category));
     $this->model->getUrlPath($product, 1);
 }