Skip to content

Commit

Permalink
fixed unit test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutosh committed Oct 28, 2018
1 parent 09586e4 commit 1638891
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/code/Magento/Quote/Model/Quote/Item/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ public function prepare(Item $item, DataObject $request, Product $candidate)
$item->setData(CartItemInterface::KEY_QTY, 0);
}
$item->addQty($candidate->getCartQty());
$item->setPrice($item->getProduct()->getFinalPrice());

$customPrice = $request->getCustomPrice();
$item->setPrice($candidate->getFinalPrice());
if (!empty($customPrice)) {
$item->setCustomPrice($customPrice);
$item->setOriginalCustomPrice($customPrice);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ protected function setUp()
'addQty',
'setCustomPrice',
'setOriginalCustomPrice',
'setData'
'setData',
'setprice'
]);
$this->quoteItemFactoryMock->expects($this->any())
->method('create')
Expand All @@ -98,7 +99,7 @@ protected function setUp()

$this->productMock = $this->createPartialMock(
\Magento\Catalog\Model\Product::class,
['getCustomOptions', '__wakeup', 'getParentProductId', 'getCartQty', 'getStickWithinParent']
['getCustomOptions', '__wakeup', 'getParentProductId', 'getCartQty', 'getStickWithinParent', 'getFinalPrice']
);
$this->objectMock = $this->createPartialMock(
\Magento\Framework\DataObject::class,
Expand Down Expand Up @@ -239,13 +240,17 @@ public function testPrepare()
$customPrice = 400000000;
$itemId = 1;
$requestItemId = 1;
$finalPrice = 1000000000;

$this->productMock->expects($this->any())
->method('getCartQty')
->will($this->returnValue($qty));
$this->productMock->expects($this->any())
->method('getStickWithinParent')
->will($this->returnValue(false));
$this->productMock->expects($this->once())
->method('getFinalPrice')
->will($this->returnValue($finalPrice));

$this->itemMock->expects($this->once())
->method('addQty')
Expand All @@ -255,6 +260,9 @@ public function testPrepare()
->will($this->returnValue($itemId));
$this->itemMock->expects($this->never())
->method('setData');
$this->itemMock->expects($this->once())
->method('setPrice')
->will($this->returnValue($this->itemMock));

$this->objectMock->expects($this->any())
->method('getCustomPrice')
Expand Down Expand Up @@ -282,13 +290,17 @@ public function testPrepareWithResetCountAndStick()
$customPrice = 400000000;
$itemId = 1;
$requestItemId = 1;
$finalPrice = 1000000000;

$this->productMock->expects($this->any())
->method('getCartQty')
->will($this->returnValue($qty));
$this->productMock->expects($this->any())
->method('getStickWithinParent')
->will($this->returnValue(true));
$this->productMock->expects($this->once())
->method('getFinalPrice')
->will($this->returnValue($finalPrice));

$this->itemMock->expects($this->once())
->method('addQty')
Expand All @@ -298,6 +310,9 @@ public function testPrepareWithResetCountAndStick()
->will($this->returnValue($itemId));
$this->itemMock->expects($this->never())
->method('setData');
$this->itemMock->expects($this->once())
->method('setPrice')
->will($this->returnValue($this->itemMock));

$this->objectMock->expects($this->any())
->method('getCustomPrice')
Expand Down Expand Up @@ -325,13 +340,17 @@ public function testPrepareWithResetCountAndNotStickAndOtherItemId()
$customPrice = 400000000;
$itemId = 1;
$requestItemId = 2;
$finalPrice = 1000000000;

$this->productMock->expects($this->any())
->method('getCartQty')
->will($this->returnValue($qty));
$this->productMock->expects($this->any())
->method('getStickWithinParent')
->will($this->returnValue(false));
$this->productMock->expects($this->once())
->method('getFinalPrice')
->will($this->returnValue($finalPrice));

$this->itemMock->expects($this->once())
->method('addQty')
Expand All @@ -341,6 +360,9 @@ public function testPrepareWithResetCountAndNotStickAndOtherItemId()
->will($this->returnValue($itemId));
$this->itemMock->expects($this->never())
->method('setData');
$this->itemMock->expects($this->once())
->method('setPrice')
->will($this->returnValue($this->itemMock));

$this->objectMock->expects($this->any())
->method('getCustomPrice')
Expand Down Expand Up @@ -368,6 +390,7 @@ public function testPrepareWithResetCountAndNotStickAndSameItemId()
$customPrice = 400000000;
$itemId = 1;
$requestItemId = 1;
$finalPrice = 1000000000;

$this->objectMock->expects($this->any())
->method('getResetCount')
Expand All @@ -386,10 +409,16 @@ public function testPrepareWithResetCountAndNotStickAndSameItemId()
$this->productMock->expects($this->any())
->method('getStickWithinParent')
->will($this->returnValue(false));
$this->productMock->expects($this->once())
->method('getFinalPrice')
->will($this->returnValue($finalPrice));

$this->itemMock->expects($this->once())
->method('addQty')
->with($qty);
$this->itemMock->expects($this->once())
->method('setPrice')
->will($this->returnValue($this->itemMock));

$this->objectMock->expects($this->any())
->method('getCustomPrice')
Expand Down

0 comments on commit 1638891

Please sign in to comment.