public function testAttachConditionToCollection()
 {
     $collection = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Collection\\AbstractCollection', ['getResource', 'getSelect'], [], '', false);
     $combine = $this->getMock('\\Magento\\Rule\\Model\\Condition\\Combine', ['getConditions'], [], '', false);
     $resource = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['getConnection'], [], '', false);
     $select = $this->getMock('\\Magento\\Framework\\DB\\Select', ['where'], [], '', false);
     $select->expects($this->never())->method('where');
     $connection = $this->getMockForAbstractClass('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface', [], '', false);
     $collection->expects($this->once())->method('getResource')->will($this->returnValue($resource));
     $collection->expects($this->any())->method('getSelect')->will($this->returnValue($select));
     $resource->expects($this->once())->method('getConnection')->will($this->returnValue($connection));
     $combine->expects($this->any())->method('getConditions')->will($this->returnValue([]));
     $this->_builder->attachConditionToCollection($collection, $combine);
 }
Beispiel #2
0
 /**
  * Test public `createCollection` method and protected `getPageSize` method via `createCollection`
  *
  * @param bool $pagerEnable
  * @param int $productsCount
  * @param int $productsPerPage
  * @param int $expectedPageSize
  * @dataProvider createCollectionDataProvider
  */
 public function testCreateCollection($pagerEnable, $productsCount, $productsPerPage, $expectedPageSize)
 {
     $this->visibility->expects($this->once())->method('getVisibleInCatalogIds')->willReturn([Visibility::VISIBILITY_IN_CATALOG, Visibility::VISIBILITY_BOTH]);
     $collection = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Resource\\Product\\Collection')->setMethods(['setVisibility', 'addMinimalPrice', 'addFinalPrice', 'addTaxPercents', 'addAttributeToSelect', 'addUrlRewrite', 'addStoreFilter', 'setPageSize', 'setCurPage'])->disableOriginalConstructor()->getMock();
     $collection->expects($this->once())->method('setVisibility')->with([Visibility::VISIBILITY_IN_CATALOG, Visibility::VISIBILITY_BOTH])->willReturnSelf();
     $collection->expects($this->once())->method('addMinimalPrice')->willReturnSelf();
     $collection->expects($this->once())->method('addFinalPrice')->willReturnSelf();
     $collection->expects($this->once())->method('addTaxPercents')->willReturnSelf();
     $collection->expects($this->once())->method('addAttributeToSelect')->willReturnSelf();
     $collection->expects($this->once())->method('addUrlRewrite')->willReturnSelf();
     $collection->expects($this->once())->method('addStoreFilter')->willReturnSelf();
     $collection->expects($this->once())->method('setPageSize')->with($expectedPageSize)->willReturnSelf();
     $collection->expects($this->once())->method('setCurPage')->willReturnSelf();
     $this->collectionFactory->expects($this->once())->method('create')->willReturn($collection);
     $this->productsList->setData('conditions_encoded', 'some_serialized_conditions');
     $conditions = $this->getMockBuilder('\\Magento\\Rule\\Model\\Condition\\Combine')->setMethods(['collectValidatedAttributes'])->disableOriginalConstructor()->getMock();
     $conditions->expects($this->once())->method('collectValidatedAttributes')->with($collection)->willReturnSelf();
     $this->builder->expects($this->once())->method('attachConditionToCollection')->with($collection, $conditions)->willReturnSelf();
     $this->rule->expects($this->once())->method('loadPost')->willReturnSelf();
     $this->rule->expects($this->once())->method('getConditions')->willReturn($conditions);
     if ($productsPerPage) {
         $this->productsList->setData('products_per_page', $productsPerPage);
     } else {
         $this->productsList->unsetData('products_per_page');
     }
     $this->productsList->setData('show_pager', $pagerEnable);
     $this->productsList->setData('products_count', $productsCount);
     $this->assertSame($collection, $this->productsList->createCollection());
 }
 /**
  * Prepare and return product collection
  *
  * @return \Magento\Catalog\Model\Resource\Product\Collection
  */
 public function createCollection()
 {
     /** @var $collection \Magento\Catalog\Model\Resource\Product\Collection */
     $collection = $this->productCollectionFactory->create();
     $collection->setVisibility($this->catalogProductVisibility->getVisibleInCatalogIds());
     $collection = $this->_addProductAttributesAndPrices($collection)->addStoreFilter()->setPageSize($this->getProductsPerPage())->setCurPage($this->getRequest()->getParam(self::PAGE_VAR_NAME, 1));
     $conditions = $this->getConditions();
     $conditions->collectValidatedAttributes($collection);
     $this->sqlBuilder->attachConditionToCollection($collection, $conditions);
     return $collection;
 }