Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
QtyincrementsTest.php
Go to the documentation of this file.
1 <?php
7 
11 class QtyincrementsTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $block;
17 
21  protected $registryMock;
22 
26  protected $stockItem;
27 
31  protected $stockRegistry;
32 
33  protected function setUp()
34  {
35  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
36  $this->registryMock = $this->createMock(\Magento\Framework\Registry::class);
37  $this->stockItem = $this->getMockBuilder(\Magento\CatalogInventory\Api\Data\StockItemInterface::class)
38  ->setMethods(['getQtyIncrements', 'getStockItem'])
39  ->getMockForAbstractClass();
40  $this->stockItem->expects($this->any())->method('getStockItem')->willReturn(1);
41  $this->stockRegistry = $this->getMockForAbstractClass(
42  \Magento\CatalogInventory\Api\StockRegistryInterface::class,
43  ['getStockItem'],
44  '',
45  false
46  );
47  $this->stockRegistry->expects($this->any())->method('getStockItem')->willReturn($this->stockItem);
48 
49  $this->block = $objectManager->getObject(
50  \Magento\CatalogInventory\Block\Qtyincrements::class,
51  [
52  'registry' => $this->registryMock,
53  'stockRegistry' => $this->stockRegistry
54  ]
55  );
56  }
57 
58  protected function tearDown()
59  {
60  $this->block = null;
61  }
62 
63  public function testGetIdentities()
64  {
65  $productTags = ['catalog_product_1'];
66  $product = $this->createMock(\Magento\Catalog\Model\Product::class);
67  $product->expects($this->once())->method('getIdentities')->will($this->returnValue($productTags));
68  $store = $this->createPartialMock(\Magento\Store\Model\Store::class, ['getWebsiteId', '__wakeup']);
69  $store->expects($this->any())->method('getWebsiteId')->willReturn(0);
70  $product->expects($this->any())->method('getStore')->will($this->returnValue($store));
71  $this->registryMock->expects($this->once())
72  ->method('registry')
73  ->with('current_product')
74  ->will($this->returnValue($product));
75  $this->assertEquals($productTags, $this->block->getIdentities());
76  }
77 
86  {
87  $this->stockItem->expects($this->once())
88  ->method('getQtyIncrements')
89  ->will($this->returnValue($qtyInc));
90 
91  $product = $this->createMock(\Magento\Catalog\Model\Product::class);
92  $product->expects($this->once())->method('getId')->will($this->returnValue($productId));
93  $product->expects($this->once())->method('isSaleable')->will($this->returnValue($isSaleable));
94  $store = $this->createPartialMock(\Magento\Store\Model\Store::class, ['getWebsiteId', '__wakeup']);
95  $store->expects($this->any())->method('getWebsiteId')->willReturn(0);
96  $product->expects($this->any())->method('getStore')->will($this->returnValue($store));
97 
98  $this->registryMock->expects($this->any())
99  ->method('registry')
100  ->with('current_product')
101  ->will($this->returnValue($product));
102 
103  $this->assertSame($result, $this->block->getProductQtyIncrements());
104  // test lazy load
105  $this->assertSame($result, $this->block->getProductQtyIncrements());
106  }
107 
112  {
113  return [
114  [1, 100, true, 100],
115  [1, 100, false, false],
116  ];
117  }
118 }
testGetProductQtyIncrements($productId, $qtyInc, $isSaleable, $result)
$objectManager
Definition: bootstrap.php:17
$isSaleable