Exemplo n.º 1
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGetProductCollection()
 {
     $storeId = 1;
     $categoryChildren = 'children';
     $visibleInCatalogIds = 1;
     $this->visibility->expects($this->once())->method('getVisibleInCatalogIds')->will($this->returnValue($visibleInCatalogIds));
     $products = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', ['setStoreId', 'addAttributeToSort', 'setVisibility', 'setCurPage', 'setPageSize', 'addCountToCategories'], [], '', false);
     $resourceCollection = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Collection\\AbstractCollection', ['addAttributeToSelect', 'addAttributeToFilter', 'addIdFilter', 'load'], [], '', false);
     $resourceCollection->expects($this->exactly(3))->method('addAttributeToSelect')->will($this->returnSelf());
     $resourceCollection->expects($this->once())->method('addAttributeToFilter')->will($this->returnSelf());
     $resourceCollection->expects($this->once())->method('addIdFilter')->with($categoryChildren)->will($this->returnSelf());
     $resourceCollection->expects($this->once())->method('load')->will($this->returnSelf());
     $products->expects($this->once())->method('addCountToCategories')->with($resourceCollection);
     $products->expects($this->once())->method('addAttributeToSort')->with('updated_at', 'desc')->will($this->returnSelf());
     $products->expects($this->once())->method('setVisibility')->with($visibleInCatalogIds)->will($this->returnSelf());
     $products->expects($this->once())->method('setCurPage')->with(1)->will($this->returnSelf());
     $products->expects($this->once())->method('setPageSize')->with(50)->will($this->returnSelf());
     $products->expects($this->once())->method('setStoreId')->with($storeId);
     $this->collectionFactory->expects($this->once())->method('create')->will($this->returnValue($products));
     $category = $this->getMock('Magento\\Catalog\\Model\\Category', ['getResourceCollection', 'getChildren', 'getProductCollection', '__wakeup'], [], '', false);
     $category->expects($this->once())->method('getResourceCollection')->will($this->returnValue($resourceCollection));
     $category->expects($this->once())->method('getChildren')->will($this->returnValue($categoryChildren));
     $category->expects($this->once())->method('getProductCollection')->will($this->returnValue($products));
     $layer = $this->getMock('Magento\\Catalog\\Model\\Layer', ['setCurrentCategory', 'prepareProductCollection', 'getProductCollection', '__wakeup'], [], '', false);
     $layer->expects($this->once())->method('setCurrentCategory')->with($category)->will($this->returnSelf());
     $layer->expects($this->once())->method('getProductCollection')->will($this->returnValue($products));
     /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Layer\Resolver $layerResolver */
     $layerResolver = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Resolver')->disableOriginalConstructor()->setMethods(['get', 'create'])->getMock();
     $layerResolver->expects($this->any())->method($this->anything())->will($this->returnValue($layer));
     $this->categoryLayer->expects($this->once())->method('setStore')->with($storeId)->will($this->returnValue($layer));
     $this->assertEquals($products, $this->model->getProductCollection($category, $storeId));
 }
Exemplo n.º 2
0
 /**
  * Retrieve list of filterable attributes
  *
  * @return array|\Magento\Catalog\Model\Resource\Product\Attribute\Collection
  */
 public function getList()
 {
     $setIds = $this->layer->getProductCollection()->getSetIds();
     if (!$setIds) {
         return array();
     }
     /** @var $collection \Magento\Catalog\Model\Resource\Product\Attribute\Collection */
     $collection = $this->collectionFactory->create();
     $collection->setItemObjectClass('Magento\\Catalog\\Model\\Resource\\Eav\\Attribute')->setAttributeSetFilter($setIds)->addStoreLabel($this->storeManager->getStore()->getId())->setOrder('position', 'ASC');
     $collection = $this->_prepareAttributeCollection($collection);
     $collection->load();
     return $collection;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function prepareProductCollection($collection)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'prepareProductCollection');
     if (!$pluginInfo) {
         return parent::prepareProductCollection($collection);
     } else {
         return $this->___callPlugins('prepareProductCollection', func_get_args(), $pluginInfo);
     }
 }
Exemplo n.º 4
0
 public function testGetState()
 {
     $state = $this->_model->getState();
     $this->assertInstanceOf('Magento\\Catalog\\Model\\Layer\\State', $state);
     $this->assertSame($state, $this->_model->getState());
     $state = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Layer\\State');
     $this->_model->setState($state);
     // $this->_model->setData('state', state);
     $this->assertSame($state, $this->_model->getState());
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function offsetGet($offset)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'offsetGet');
     if (!$pluginInfo) {
         return parent::offsetGet($offset);
     } else {
         return $this->___callPlugins('offsetGet', func_get_args(), $pluginInfo);
     }
 }
Exemplo n.º 6
0
 /**
  * Enter description here...
  *
  * @return Category
  */
 public function getCurrentCategory()
 {
     return $this->_catalogLayer->getCurrentCategory();
 }