Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SpecialTest.php
Go to the documentation of this file.
1 <?php
7 
9 
14 class SpecialTest extends \PHPUnit\Framework\TestCase
15 {
19  protected $special;
20 
25 
29  protected $productFactory;
30 
34  protected $product;
35 
39  protected $storeManager;
40 
41  protected function setUp()
42  {
43  $this->product = $this->createMock(\Magento\Catalog\Model\Product::class);
44  $this->productFactory = $this->createPartialMock(\Magento\Catalog\Model\ProductFactory::class, ['create']);
45  $this->productFactory->expects($this->any())->method('create')->will($this->returnValue($this->product));
46  $this->storeManager = $this->createMock(\Magento\Store\Model\StoreManager::class);
47 
48  $this->objectManagerHelper = new ObjectManagerHelper($this);
49  $this->special = $this->objectManagerHelper->getObject(
50  \Magento\Catalog\Model\Rss\Product\Special::class,
51  [
52  'productFactory' => $this->productFactory,
53  'storeManager' => $this->storeManager
54  ]
55  );
56  }
57 
58  public function testGetProductsCollection()
59  {
60  $storeId = 1;
61  $store = $this->createMock(\Magento\Store\Model\Store::class);
62  $this->storeManager->expects($this->once())->method('getStore')->with($storeId)->will(
63  $this->returnValue($store)
64  );
65  $websiteId = 1;
66  $store->expects($this->once())->method('getWebsiteId')->will($this->returnValue($websiteId));
67 
70  $this->createMock(\Magento\Catalog\Model\ResourceModel\Product\Collection::class);
71  $this->product->expects($this->once())->method('getResourceCollection')->will(
72  $this->returnValue($productCollection)
73  );
74  $customerGroupId = 1;
75  $productCollection->expects($this->once())->method('addPriceDataFieldFilter')->will($this->returnSelf());
76  $productCollection->expects($this->once())->method('addPriceData')->with($storeId, $customerGroupId)->will(
77  $this->returnSelf()
78  );
79  $productCollection->expects($this->once())->method('addAttributeToSelect')->will($this->returnSelf());
80  $productCollection->expects($this->once())->method('addAttributeToSort')->will($this->returnSelf());
81 
82  $products = $this->special->getProductsCollection($storeId, $customerGroupId);
83  $this->assertEquals($productCollection, $products);
84  }
85 }