Skip to content

Commit ff1962a

Browse files
author
Roman Ganin
committed
Merge branch 'develop' of github.corp.ebay.com:magento2/magento2ce into MAGETWO-39187
2 parents 8b354bc + 62f5876 commit ff1962a

File tree

33 files changed

+1429
-96
lines changed

33 files changed

+1429
-96
lines changed

app/code/Magento/CatalogInventory/Model/Adminhtml/Stock/Item.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
use Magento\Customer\Api\GroupManagementInterface;
1212
use Magento\Framework\Api\AttributeValueFactory;
1313
use Magento\Framework\Api\ExtensionAttributesFactory;
14+
use Magento\Framework\Object\IdentityInterface;
15+
use Magento\Catalog\Model\Product;
1416

1517
/**
1618
* Catalog Inventory Stock Model for adminhtml area
1719
* @method \Magento\CatalogInventory\Api\Data\StockItemExtensionInterface getExtensionAttributes()
1820
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1921
*/
20-
class Item extends \Magento\CatalogInventory\Model\Stock\Item
22+
class Item extends \Magento\CatalogInventory\Model\Stock\Item implements IdentityInterface
2123
{
2224
/**
2325
* @var GroupManagementInterface
@@ -122,4 +124,17 @@ public function getShowDefaultNotificationMessage()
122124
{
123125
return true;
124126
}
127+
128+
/**
129+
* @inheritdoc
130+
*/
131+
public function getIdentities()
132+
{
133+
$tags = [];
134+
if ($this->getProductId()) {
135+
$tags[] = Product::CACHE_TAG . '_' . $this->getProductId();
136+
}
137+
138+
return $tags;
139+
}
125140
}

app/code/Magento/CatalogInventory/Model/Resource/Stock/Item.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ protected function _afterSave(AbstractModel $object)
123123
parent::_afterSave($object);
124124
/** @var StockItemInterface $object */
125125
if ($this->processIndexEvents) {
126+
$this->stockIndexerProcessor->markIndexerAsInvalid();
126127
$this->stockIndexerProcessor->reindexRow($object->getProductId());
127128
}
128129
return $this;

app/code/Magento/CatalogInventory/Model/StockRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public function getLowStockItems($websiteId, $qty, $currentPage = 1, $pageSize =
172172
$criteria = $this->criteriaFactory->create();
173173
$criteria->setLimit($currentPage, $pageSize);
174174
$criteria->setWebsiteFilter($websiteId);
175-
$criteria->setQtyFilter('>=', $qty);
175+
$criteria->setQtyFilter('<=', $qty);
176176
$criteria->addField('qty');
177177
return $this->stockItemRepository->getList($criteria);
178178
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogInventory\Test\Unit\Block\Plugin;
7+
8+
class ProductViewTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\CatalogInventory\Block\Plugin\ProductView
12+
*/
13+
protected $block;
14+
15+
/**
16+
* @var \Magento\CatalogInventory\Api\Data\StockItemInterface|\PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $stockItem;
19+
20+
/**
21+
* @var \Magento\CatalogInventory\Api\StockRegistryInterface|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
protected $stockRegistry;
24+
25+
protected function setUp()
26+
{
27+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
28+
29+
$this->stockItem = $this->getMockBuilder('\Magento\CatalogInventory\Model\Stock\Item')
30+
->disableOriginalConstructor()
31+
->setMethods(['getQtyMinAllowed', 'getQtyMaxAllowed', 'getQtyIncrements'])
32+
->getMock();
33+
34+
$this->stockRegistry = $this->getMockBuilder('Magento\CatalogInventory\Api\StockRegistryInterface')
35+
->getMock();
36+
37+
$this->block = $objectManager->getObject(
38+
'Magento\CatalogInventory\Block\Plugin\ProductView',
39+
[
40+
'stockRegistry' => $this->stockRegistry
41+
]
42+
);
43+
}
44+
45+
public function testAfterGetQuantityValidators()
46+
{
47+
$result = [
48+
'validate-item-quantity' =>
49+
[
50+
'minAllowed' => 2,
51+
'maxAllowed' => 5,
52+
'qtyIncrements' => 3
53+
]
54+
];
55+
$validators = [];
56+
$productViewBlock = $this->getMockBuilder('Magento\Catalog\Block\Product\View')
57+
->disableOriginalConstructor()
58+
->getMock();
59+
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
60+
->disableOriginalConstructor()
61+
->setMethods(['_wakeup', 'getId', 'getStore'])
62+
->getMock();
63+
$storeMock = $this->getMockBuilder('Magento\Store\Model\Store')
64+
->disableOriginalConstructor()
65+
->setMethods(['getWebsiteId', '_wakeup'])
66+
->getMock();
67+
68+
$productViewBlock->expects($this->any())->method('getProduct')->willReturn($productMock);
69+
$productMock->expects($this->once())->method('getId')->willReturn('productId');
70+
$productMock->expects($this->once())->method('getStore')->willReturn($storeMock);
71+
$storeMock->expects($this->once())->method('getWebsiteId')->willReturn('websiteId');
72+
$this->stockRegistry->expects($this->once())
73+
->method('getStockItem')
74+
->with('productId', 'websiteId')
75+
->willReturn($this->stockItem);
76+
$this->stockItem->expects($this->once())->method('getQtyMinAllowed')->willReturn(2);
77+
$this->stockItem->expects($this->any())->method('getQtyMaxAllowed')->willReturn(5);
78+
$this->stockItem->expects($this->any())->method('getQtyIncrements')->willReturn(3);
79+
80+
$this->assertEquals($result, $this->block->afterGetQuantityValidators($productViewBlock, $validators));
81+
}
82+
}

app/code/Magento/CatalogInventory/Test/Unit/Block/Stockqty/DefaultStockqtyTest.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class DefaultStockqtyTest extends \PHPUnit_Framework_TestCase
3030
*/
3131
protected $stockRegistryMock;
3232

33+
/**
34+
* @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
35+
*/
36+
protected $scopeConfigMock;
37+
3338
protected function setUp()
3439
{
3540
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
@@ -44,12 +49,16 @@ protected function setUp()
4449
$this->stockRegistryMock = $this->getMockBuilder('Magento\CatalogInventory\Api\StockRegistryInterface')
4550
->disableOriginalConstructor()
4651
->getMock();
52+
$this->scopeConfigMock = $this->getMockBuilder('\Magento\Framework\App\Config\ScopeConfigInterface')
53+
->disableOriginalConstructor()
54+
->getMock();
4755
$this->block = $objectManager->getObject(
4856
'Magento\CatalogInventory\Block\Stockqty\DefaultStockqty',
4957
[
5058
'registry' => $this->registryMock,
5159
'stockState' => $this->stockState,
52-
'stockRegistry' => $this->stockRegistryMock
60+
'stockRegistry' => $this->stockRegistryMock,
61+
'scopeConfig' => $this->scopeConfigMock
5362
]
5463
);
5564
}
@@ -198,4 +207,10 @@ protected function setDataArrayValue($key, $value)
198207
$dataArray[$key] = $value;
199208
$property->setValue($this->block, $dataArray);
200209
}
210+
211+
public function testGetThresholdQty()
212+
{
213+
$this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(5);
214+
$this->assertEquals(5, $this->block->getThresholdQty());
215+
}
201216
}

app/code/Magento/CatalogInventory/Test/Unit/Model/Adminhtml/Stock/ItemTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,10 @@ public function testGetCustomerGroupId()
5858
$this->_model->setCustomerGroupId(2);
5959
$this->assertEquals(2, $this->_model->getCustomerGroupId());
6060
}
61+
62+
public function testGetIdentities()
63+
{
64+
$this->_model->setProductId(1);
65+
$this->assertEquals(['catalog_product_1'], $this->_model->getIdentities());
66+
}
6167
}

app/code/Magento/CatalogInventory/Test/Unit/Model/ConfigurationTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,14 @@ public function testGetConfigItemOptions()
259259
];
260260
$this->assertEquals($fields, $this->model->getConfigItemOptions());
261261
}
262+
263+
public function testGetManageStock()
264+
{
265+
$store = 1;
266+
$this->scopeConfigMock->expects($this->once())
267+
->method('isSetFlag')
268+
->with(Configuration::XML_PATH_MANAGE_STOCK, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store)
269+
->willReturn(1);
270+
$this->assertEquals(1, $this->model->getManageStock($store));
271+
}
262272
}

app/code/Magento/CatalogInventory/Test/Unit/Model/Stock/ItemTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,4 +403,58 @@ public function testGetLowStockDate()
403403
$this->item->setLowStockDate($date);
404404
$this->assertEquals($date, $this->item->getLowStockDate());
405405
}
406+
407+
/**
408+
* @param array $config
409+
* @param mixed $expected
410+
* @dataProvider getQtyIncrementsDataProvider(
411+
*/
412+
public function testGetQtyIncrements($config, $expected)
413+
{
414+
$this->setDataArrayValue('qty_increments', $config['qty_increments']);
415+
$this->setDataArrayValue('enable_qty_increments', $config['enable_qty_increments']);
416+
$this->setDataArrayValue('use_config_qty_increments', $config['use_config_qty_increments']);
417+
if ($config['use_config_qty_increments']) {
418+
$this->stockConfiguration->expects($this->once())
419+
->method('getQtyIncrements')
420+
->with($this->storeId)
421+
->willReturn($config['qty_increments']);
422+
} else {
423+
$this->setDataArrayValue('qty_increments', $config['qty_increments']);
424+
}
425+
$this->assertEquals($expected, $this->item->getQtyIncrements());
426+
}
427+
428+
/**
429+
* @return array
430+
*/
431+
public function getQtyIncrementsDataProvider()
432+
{
433+
return [
434+
[
435+
[
436+
'qty_increments' => 1,
437+
'enable_qty_increments' => true,
438+
'use_config_qty_increments' => true
439+
],
440+
1
441+
],
442+
[
443+
[
444+
'qty_increments' => -2,
445+
'enable_qty_increments' => true,
446+
'use_config_qty_increments' => true
447+
],
448+
false
449+
],
450+
[
451+
[
452+
'qty_increments' => 3,
453+
'enable_qty_increments' => true,
454+
'use_config_qty_increments' => false
455+
],
456+
3
457+
],
458+
];
459+
}
406460
}

0 commit comments

Comments
 (0)