Exemplo n.º 1
0
 public function testGetCategories()
 {
     $this->categoryCollectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->categoryCollectionMock = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->setMethods(['addNameToResult', 'addUrlRewriteToResult', 'addParentPathFilter', 'addStoreFilter', 'addIsActiveFilter', 'addAttributeToFilter', 'addSortedField', 'load'])->getMock();
     $this->categoryCollectionMock->expects($this->once())->method('addNameToResult')->willReturn($this->categoryCollectionMock);
     $this->categoryCollectionMock->expects($this->once())->method('addUrlRewriteToResult')->willReturn($this->categoryCollectionMock);
     $this->categoryCollectionMock->expects($this->once())->method('addParentPathFilter')->with(self::PARENT_PATH)->willReturn($this->categoryCollectionMock);
     $this->categoryCollectionMock->expects($this->once())->method('addStoreFilter')->willReturn($this->categoryCollectionMock);
     $this->categoryCollectionMock->expects($this->once())->method('addIsActiveFilter')->willReturn($this->categoryCollectionMock);
     $this->categoryCollectionMock->expects($this->once())->method('addSortedField')->with(self::SORTED)->willReturn($this->categoryCollectionMock);
     $this->categoryCollectionMock->expects($this->once())->method('addAttributeToFilter')->with('include_in_menu', 1)->willReturn($this->categoryCollectionMock);
     $this->categoryCollectionMock->expects($this->once())->method('load')->willReturn($this->categoryCollectionMock);
     $this->categoryCollectionFactoryMock->expects($this->once())->method('create')->willReturn($this->categoryCollectionMock);
     $this->model = $this->objectManager->getObject(Flat::class, ['context' => $this->contextMock, 'storeManager' => $this->storeManagerMock]);
     $reflection = new \ReflectionClass(get_class($this->model));
     $reflectionProperty = $reflection->getProperty('categoryFlatCollectionFactory');
     $reflectionProperty->setAccessible(true);
     $reflectionProperty->setValue($this->model, $this->categoryCollectionFactoryMock);
     $this->assertEquals($this->model->getCategories(self::PARENT, self::RECURSION_LEVEL, self::SORTED, true), $this->categoryCollectionMock);
 }