Skip to content
Snippets Groups Projects
Commit 2c03fa68 authored by Anton Guz's avatar Anton Guz
Browse files

Merge remote-tracking branch 'vanilla/develop' into PR

parents 81062987 c0658aba
Branches
No related merge requests found
......@@ -94,7 +94,7 @@ class Processor
/**
* We specify qty after we know about parent (for stock)
*/
if ($request->getResetCount()) {
if ($request->getResetCount() && !$candidate->getStickWithinParent() && $item->getId() == $request->getId()) {
$item->setData(CartItemInterface::KEY_QTY, 0);
}
$item->addQty($candidate->getCartQty());
......
......@@ -72,7 +72,16 @@ class ProcessorTest extends \PHPUnit_Framework_TestCase
$this->itemMock = $this->getMock(
'Magento\Quote\Model\Quote\Item',
['getId', 'setOptions', '__wakeup', 'setProduct', 'addQty', 'setCustomPrice', 'setOriginalCustomPrice'],
[
'getId',
'setOptions',
'__wakeup',
'setProduct',
'addQty',
'setCustomPrice',
'setOriginalCustomPrice',
'setData'
],
[],
'',
false
......@@ -109,7 +118,7 @@ class ProcessorTest extends \PHPUnit_Framework_TestCase
$this->productMock = $this->getMock(
'Magento\Catalog\Model\Product',
['getCustomOptions', '__wakeup', 'getParentProductId', 'getCartQty'],
['getCustomOptions', '__wakeup', 'getParentProductId', 'getCartQty', 'getStickWithinParent'],
[],
'',
false
......@@ -148,8 +157,12 @@ class ProcessorTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue($itemId));
$this->itemMock->expects($this->any())
->method('setData')
->with($this->equalTo('qty'), $this->equalTo(0));
->willReturnMap(
[
['store_id', $storeId],
['qty', 0],
]
);
$this->storeMock->expects($this->any())
->method('getId')
......@@ -177,7 +190,6 @@ class ProcessorTest extends \PHPUnit_Framework_TestCase
->method('getParentProductId')
->will($this->returnValue(true));
$this->itemMock->expects($this->never())->method('setOptions');
$this->itemMock->expects($this->never())->method('setProduct');
......@@ -185,7 +197,13 @@ class ProcessorTest extends \PHPUnit_Framework_TestCase
->method('getId')
->will($this->returnValue($itemId));
$this->itemMock->expects($this->never())->method('setData');
$this->itemMock->expects($this->any())
->method('setData')
->willReturnMap(
[
['store_id', $storeId],
]
);
$this->storeMock->expects($this->any())
->method('getId')
......@@ -222,7 +240,13 @@ class ProcessorTest extends \PHPUnit_Framework_TestCase
->method('getId')
->will($this->returnValue($itemId));
$this->itemMock->expects($this->never())->method('setData');
$this->itemMock->expects($this->any())
->method('setData')
->willReturnMap(
[
['store_id', $storeId],
]
);
$this->storeMock->expects($this->any())
->method('getId')
......@@ -238,58 +262,171 @@ class ProcessorTest extends \PHPUnit_Framework_TestCase
{
$qty = 3000000000;
$customPrice = 400000000;
$itemId = 1;
$requestItemId = 1;
$this->productMock->expects($this->any())
->method('getCartQty')
->will($this->returnValue($qty));
$this->productMock->expects($this->any())
->method('getStickWithinParent')
->will($this->returnValue(false));
$this->itemMock->expects($this->any())
$this->itemMock->expects($this->once())
->method('addQty')
->with($qty);
$this->itemMock->expects($this->any())
->method('getId')
->will($this->returnValue($itemId));
$this->itemMock->expects($this->never())
->method('setData');
$this->objectMock->expects($this->any())
->method('getCustomPrice')
->will($this->returnValue($customPrice));
$this->objectMock->expects($this->any())
->method('getResetCount')
->will($this->returnValue(false));
$this->objectMock->expects($this->any())
->method('getId')
->will($this->returnValue($requestItemId));
$this->itemMock->expects($this->once())
->method('setCustomPrice')
->will($this->returnValue($customPrice));
$this->itemMock->expects($this->once())
->method('setOriginalCustomPrice')
->will($this->returnValue($customPrice));
$this->processor->prepare($this->itemMock, $this->objectMock, $this->productMock);
}
public function testPrepareWithResetCountAndStick()
{
$qty = 3000000000;
$customPrice = 400000000;
$itemId = 1;
$requestItemId = 1;
$this->productMock->expects($this->any())
->method('getCartQty')
->will($this->returnValue($qty));
$this->productMock->expects($this->any())
->method('getStickWithinParent')
->will($this->returnValue(true));
$this->itemMock->expects($this->once())
->method('addQty')
->with($qty);
$this->itemMock->expects($this->any())
->method('getId')
->will($this->returnValue($itemId));
$this->itemMock->expects($this->never())
->method('setData');
$this->objectMock->expects($this->any())
->method('getCustomPrice')
->will($this->returnValue($customPrice));
$this->objectMock->expects($this->any())
->method('getResetCount')
->will($this->returnValue(true));
$this->objectMock->expects($this->any())
->method('getId')
->will($this->returnValue($requestItemId));
$this->itemMock->expects($this->once())
->method('setCustomPrice')
->will($this->returnValue($customPrice));
$this->itemMock->expects($this->once())
->method('setOriginalCustomPrice')
->will($this->returnValue($customPrice));
$this->processor->prepare($this->itemMock, $this->objectMock, $this->productMock);
}
public function testPrepareWithResetCountAndNotStickAndOtherItemId()
{
$qty = 3000000000;
$customPrice = 400000000;
$itemId = 1;
$requestItemId = 2;
$this->productMock->expects($this->any())
->method('getCartQty')
->will($this->returnValue($qty));
$this->productMock->expects($this->any())
->method('getStickWithinParent')
->will($this->returnValue(false));
$this->itemMock->expects($this->once())
->method('addQty')
->with($qty);
$this->itemMock->expects($this->any())
->method('getId')
->will($this->returnValue($itemId));
$this->itemMock->expects($this->never())
->method('setData');
$this->objectMock->expects($this->any())
->method('getCustomPrice')
->will($this->returnValue($customPrice));
$this->objectMock->expects($this->any())
->method('getResetCount')
->will($this->returnValue(true));
$this->objectMock->expects($this->any())
->method('getId')
->will($this->returnValue($requestItemId));
$this->itemMock->expects($this->once())
->method('setCustomPrice')
->will($this->returnValue($customPrice));
$this->itemMock->expects($this->once())
->method('setOriginalCustomPrice')
->will($this->returnValue($customPrice));
$this->processor->prepare($this->itemMock, $this->objectMock, $this->productMock);
}
public function testPrepareResetCount()
public function testPrepareWithResetCountAndNotStickAndSameItemId()
{
$qty = 3000000000;
$customPrice = 400000000;
$itemId = 1;
$requestItemId = 1;
$this->objectMock->expects($this->any())
->method('getResetCount')
->will($this->returnValue(true));
$this->itemMock->expects($this->any())
->method('getId')
->will($this->returnValue($itemId));
$this->itemMock->expects($this->once())
->method('setData')
->with(CartItemInterface::KEY_QTY, 0);
$this->productMock->expects($this->any())
->method('getCartQty')
->will($this->returnValue($qty));
$this->productMock->expects($this->any())
->method('getStickWithinParent')
->will($this->returnValue(false));
$this->itemMock->expects($this->any())
$this->itemMock->expects($this->once())
->method('addQty')
->with($qty);
$this->objectMock->expects($this->any())
->method('getCustomPrice')
->will($this->returnValue($customPrice));
$this->objectMock->expects($this->any())
->method('getId')
->will($this->returnValue($requestItemId));
$this->itemMock->expects($this->any())
$this->itemMock->expects($this->once())
->method('setCustomPrice')
->will($this->returnValue($customPrice));
$this->itemMock->expects($this->any())
$this->itemMock->expects($this->once())
->method('setOriginalCustomPrice')
->will($this->returnValue($customPrice));
......
......@@ -151,7 +151,7 @@ class Observer
$productId = $observer->getEvent()->getProduct()->getId();
$viewData['product_id'] = $productId;
$viewData['store_id'] = $this->_storeManager->getStore()->getId();
if ($this->_customerSession->isLoggedIn()) {
$viewData['customer_id'] = $this->_customerSession->getCustomerId();
} else {
......
......@@ -85,7 +85,6 @@ class ObserverTest extends \PHPUnit_Framework_TestCase
/** @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject $storeManager */
$storeManager = $this->getMock('Magento\Store\Model\StoreManagerInterface');
$this->storeMock = $this->getMockBuilder('\Magento\Store\Model\Store')
->disableOriginalConstructor()->getMock();
......@@ -128,7 +127,8 @@ class ObserverTest extends \PHPUnit_Framework_TestCase
$storeId = 1;
$expectedViewedData = [
'product_id' => $productId,
'customer_id' => $customerId
'customer_id' => $customerId,
'store_id' => $storeId,
];
$expectedEventData = [
......@@ -160,7 +160,8 @@ class ObserverTest extends \PHPUnit_Framework_TestCase
$storeId = 1;
$expectedViewedData = [
'product_id' => $productId,
'visitor_id' => $visitorId
'visitor_id' => $visitorId,
'store_id' => $storeId,
];
$expectedEventData = [
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment