67 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
69 $this->contextMock = $this->createPartialMock(
70 \
Magento\Backend\Block\Template\Context::class,
71 [
'getRequest',
'getStoreManager']
73 $this->stockConfigurationMock = $this->getMockForAbstractClass(
74 \
Magento\CatalogInventory\Api\StockConfigurationInterface::class,
79 $this->stockRegistryMock = $this->getMockForAbstractClass(
80 \
Magento\CatalogInventory\Api\StockRegistryInterface::class,
85 $this->backordersMock = $this->createMock(\
Magento\CatalogInventory\Model\Source\Backorders::class);
86 $this->stockMock = $this->createMock(\
Magento\CatalogInventory\Model\Source\Stock::class);
87 $this->coreRegistryMock = $this->createMock(\
Magento\Framework\Registry::class);
88 $this->moduleManager = $this->createMock(\
Magento\Framework\Module\Manager::class);
89 $this->storeManagerMock = $this->getMockForAbstractClass(
90 \
Magento\Store\Model\StoreManagerInterface::class,
96 $this->contextMock->expects($this->once())
97 ->method(
'getStoreManager')
98 ->will($this->returnValue($this->storeManagerMock));
101 \
Magento\Catalog\Block\Adminhtml\Product\Edit\Tab\Inventory::class,
103 'context' => $this->contextMock,
104 'backorders' => $this->backordersMock,
105 'stock' => $this->stockMock,
106 'moduleManager' => $this->moduleManager,
107 'coreRegistry' => $this->coreRegistryMock,
108 'stockRegistry' => $this->stockRegistryMock,
109 'stockConfiguration' => $this->stockConfigurationMock,
124 $this->moduleManager->expects($this->once())
125 ->method(
'isEnabled')
126 ->with(
'Magento_CatalogInventory')
127 ->will($this->returnValue($moduleEnabled));
128 if ($moduleEnabled) {
129 $this->backordersMock->expects($this->once())
130 ->method(
'toOptionArray')
131 ->will($this->returnValue([
'test-value',
'test-value']));
134 $result = $this->inventory->getBackordersOption();
135 $this->assertEquals($moduleEnabled, !empty(
$result));
148 $this->moduleManager->expects($this->once())
149 ->method(
'isEnabled')
150 ->with(
'Magento_CatalogInventory')
151 ->will($this->returnValue($moduleEnabled));
152 if ($moduleEnabled) {
153 $this->stockMock->expects($this->once())
154 ->method(
'toOptionArray')
155 ->will($this->returnValue([
'test-value',
'test-value']));
158 $result = $this->inventory->getStockOption();
159 $this->assertEquals($moduleEnabled, !empty(
$result));
169 $this->coreRegistryMock->expects($this->once())
172 ->will($this->returnValue(
'return-value'));
174 $result = $this->inventory->getProduct();
175 $this->assertEquals(
'return-value',
$result);
187 $productMock = $this->createPartialMock(\
Magento\Catalog\Model\Product::class, [
'getId',
'getStore']);
188 $storeMock = $this->createPartialMock(\
Magento\Store\Model\Store::class, [
'getWebsiteId']);
189 $productMock->expects($this->once())
192 $productMock->expects($this->once())
194 ->will($this->returnValue($storeMock));
195 $storeMock->expects($this->once())
196 ->method(
'getWebsiteId')
198 $this->coreRegistryMock->expects($this->any())
201 ->will($this->returnValue($productMock));
202 $this->stockRegistryMock->expects($this->once())
203 ->method(
'getStockItem')
205 ->will($this->returnValue(
'return-value'));
207 $resultItem = $this->inventory->getStockItem();
208 $this->assertEquals(
'return-value', $resultItem);
225 $fieldName =
'field';
227 $stockItemMock = $this->getMockForAbstractClass(
228 \
Magento\CatalogInventory\Api\Data\StockItemInterface::class,
236 $productMock = $this->createMock(\
Magento\Catalog\Model\Product::class);
237 $storeMock = $this->createMock(\
Magento\Store\Model\Store::class);
238 $productMock->expects($this->once())
241 $productMock->expects($this->once())
243 ->will($this->returnValue($storeMock));
244 $storeMock->expects($this->once())
245 ->method(
'getWebsiteId')
247 $this->coreRegistryMock->expects($this->any())
250 ->will($this->returnValue($productMock));
251 $this->stockRegistryMock->expects($this->once())
252 ->method(
'getStockItem')
254 ->will($this->returnValue($stockItemMock));
255 $stockItemMock->expects($this->once())
256 ->method(
'getItemId')
257 ->will($this->returnValue($stockId));
260 $stockItemMock->expects($this->once())
262 ->will($this->returnValue(
'call-method'));
264 if (empty(
$methods) || empty($stockId)) {
265 $this->stockConfigurationMock->expects($this->once())
266 ->method(
'getDefaultConfigValue')
267 ->will($this->returnValue(
'default-result'));
270 $resultValue = $this->inventory->getFieldValue($fieldName);
271 $this->assertEquals(
$result, $resultValue);
288 $fieldName =
'field';
290 $stockItemMock = $this->getMockForAbstractClass(
291 \
Magento\CatalogInventory\Api\Data\StockItemInterface::class,
299 $productMock = $this->createMock(\
Magento\Catalog\Model\Product::class);
300 $storeMock = $this->createMock(\
Magento\Store\Model\Store::class);
301 $productMock->expects($this->once())
304 $productMock->expects($this->once())
306 ->will($this->returnValue($storeMock));
307 $storeMock->expects($this->once())
308 ->method(
'getWebsiteId')
310 $this->coreRegistryMock->expects($this->any())
313 ->will($this->returnValue($productMock));
314 $this->stockRegistryMock->expects($this->once())
315 ->method(
'getStockItem')
317 ->will($this->returnValue($stockItemMock));
318 $stockItemMock->expects($this->once())
319 ->method(
'getItemId')
320 ->will($this->returnValue($stockId));
323 $stockItemMock->expects($this->once())
325 ->will($this->returnValue(
'call-method'));
327 if (empty(
$methods) || empty($stockId)) {
328 $this->stockConfigurationMock->expects($this->once())
329 ->method(
'getDefaultConfigValue')
330 ->will($this->returnValue(
'default-result'));
333 $resultField = $this->inventory->getConfigFieldValue($fieldName);
334 $this->assertEquals(
$result, $resultField);
344 $field =
'filed-name';
345 $this->stockConfigurationMock->expects($this->once())
346 ->method(
'getDefaultConfigValue')
347 ->will($this->returnValue(
'return-value'));
349 $result = $this->inventory->getDefaultConfigValue($field);
350 $this->assertEquals(
'return-value',
$result);
360 $productMock = $this->createPartialMock(\
Magento\Catalog\Model\Product::class, [
'getInventoryReadonly']);
361 $this->coreRegistryMock->expects($this->once())
364 ->will($this->returnValue($productMock));
366 $productMock->expects($this->once())
367 ->method(
'getInventoryReadonly')
368 ->will($this->returnValue(
'return-value'));
370 $result = $this->inventory->isReadonly();
371 $this->assertEquals(
'return-value',
$result);
385 $productMock = $this->createPartialMock(\
Magento\Catalog\Model\Product::class, [
'getId']);
386 $this->coreRegistryMock->expects($this->once())
389 ->will($this->returnValue($productMock));
390 $productMock->expects($this->once())
392 ->will($this->returnValue(
$id));
394 $methodResult = $this->inventory->isNew();
395 $this->assertEquals(
$result, $methodResult);
405 $result = $this->inventory->getFieldSuffix();
406 $this->assertEquals(
'product',
$result);
416 $productMock = $this->createPartialMock(\
Magento\Catalog\Model\Product::class, [
'getTypeInstance']);
417 $typeMock = $this->getMockForAbstractClass(
418 \
Magento\Catalog\Model\Product\Type\AbstractType::class,
424 [
'canUseQtyDecimals']
426 $this->coreRegistryMock->expects($this->once())
429 ->will($this->returnValue($productMock));
430 $productMock->expects($this->once())
431 ->method(
'getTypeInstance')
432 ->will($this->returnValue($typeMock));
433 $typeMock->expects($this->once())
434 ->method(
'canUseQtyDecimals')
435 ->will($this->returnValue(
'return-value'));
437 $result = $this->inventory->canUseQtyDecimals();
438 $this->assertEquals(
'return-value',
$result);
448 $productMock = $this->createPartialMock(\
Magento\Catalog\Model\Product::class, [
'getIsVirtual']);
449 $this->coreRegistryMock->expects($this->once())
452 ->will($this->returnValue($productMock));
453 $productMock->expects($this->once())
454 ->method(
'getIsVirtual')
455 ->will($this->returnValue(
'return-value'));
457 $result = $this->inventory->isVirtual();
458 $this->assertEquals(
'return-value',
$result);
468 $this->storeManagerMock->expects($this->once())
469 ->method(
'isSingleStoreMode')
470 ->will($this->returnValue(
'return-value'));
472 $result = $this->inventory->isSingleStoreMode();
473 $this->assertEquals(
'return-value',
$result);
485 'ModuleEnabled' =>
true,
488 'ModuleEnabled' =>
false 503 'methods' => [
'getField'],
504 'result' =>
'call-method',
509 'result' =>
'default-result' 514 'result' =>
'default-result' 529 'methods' => [
'getUseConfigField'],
530 'result' =>
'call-method',
535 'result' =>
'default-result' 540 'result' =>
'default-result'
dataProviderModuleEnabled()
testGetConfigFieldValue($stockId, $methods, $result)
testGetStockOption($moduleEnabled)
dataProviderGetFieldValue()
testGetBackordersOption($moduleEnabled)
dataProviderGetConfigFieldValue()
testGetDefaultConfigValue()
testGetFieldValue($stockId, $methods, $result)