Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StockConfigurationTest.php
Go to the documentation of this file.
1 <?php
8 
10 
14 class StockConfigurationTest extends \PHPUnit\Framework\TestCase
15 {
18 
21 
25  protected $config;
26 
30  protected $scopeConfig;
31 
35  protected $minsaleqtyHelper;
36 
37  protected function setUp()
38  {
39  $this->config = $this->getMockForAbstractClass(
40  \Magento\Catalog\Model\ProductTypes\ConfigInterface::class,
41  [],
42  '',
43  false
44  );
45  $this->scopeConfig = $this->getMockForAbstractClass(
46  \Magento\Framework\App\Config\ScopeConfigInterface::class,
47  ['isSetFlag'],
48  '',
49  false
50  );
51 
52  $this->minsaleqtyHelper = $this->createMock(\Magento\CatalogInventory\Helper\Minsaleqty::class);
53 
54  $this->objectManagerHelper = new ObjectManagerHelper($this);
55  $this->stockConfiguration = $this->objectManagerHelper->getObject(
56  \Magento\CatalogInventory\Model\Configuration::class,
57  [
58  'config' => $this->config,
59  'scopeConfig' => $this->scopeConfig,
60  'minsaleqtyHelper' => $this->minsaleqtyHelper
61  ]
62  );
63  }
64 
65  public function testGetConfigItemOptions()
66  {
67  $configOptions = [
68  'min_qty',
69  'backorders',
70  'min_sale_qty',
71  'max_sale_qty',
72  'notify_stock_qty',
73  'manage_stock',
74  'enable_qty_increments',
75  'qty_increments',
76  'is_decimal_divided',
77  ];
78  $this->assertSame($configOptions, $this->stockConfiguration->getConfigItemOptions());
79  }
80 
81  public function testIsShowOutOfStock()
82  {
83  $store = 0;
84  $this->scopeConfig->expects($this->once())
85  ->method('isSetFlag')
86  ->with(
87  \Magento\CatalogInventory\Model\Configuration::XML_PATH_SHOW_OUT_OF_STOCK,
88  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
89  $store
90  )
91  ->will($this->returnValue(true));
92  $this->assertTrue($this->stockConfiguration->isShowOutOfStock());
93  }
94 
95  public function testIsAutoReturnEnabled()
96  {
97  $store = 0;
98  $this->scopeConfig->expects($this->once())
99  ->method('isSetFlag')
100  ->with(
101  \Magento\CatalogInventory\Model\Configuration::XML_PATH_ITEM_AUTO_RETURN,
102  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
103  $store
104  )
105  ->will($this->returnValue(true));
106  $this->assertTrue($this->stockConfiguration->isAutoReturnEnabled());
107  }
108 
110  {
111  $store = 0;
112  $this->scopeConfig->expects($this->once())
113  ->method('isSetFlag')
114  ->with(
115  \Magento\CatalogInventory\Model\Configuration::XML_PATH_DISPLAY_PRODUCT_STOCK_STATUS,
116  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
117  $store
118  )
119  ->will($this->returnValue(true));
120  $this->assertTrue($this->stockConfiguration->isDisplayProductStockStatus());
121  }
122 }