Beispiel #1
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());
 }