Skip to content

Commit daaa2b4

Browse files
committed
MAGETWO-71393: Incorrect catalog rule price for bundle product with custom option
1 parent 9c5773f commit daaa2b4

File tree

3 files changed

+49
-78
lines changed

3 files changed

+49
-78
lines changed

app/code/Magento/Bundle/Test/Unit/Pricing/Price/BundleSelectionPriceTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ public function testGetValueTypeFixedWithSelectionPriceType($useRegularPrice)
201201
[
202202
['qty', null, 1],
203203
['final_price', null, 100],
204+
['price', null, 100],
204205
]
205206
)
206207
);

app/code/Magento/Catalog/Test/Unit/Model/Product/Option/ValueTest.php

Lines changed: 34 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,32 @@ class ValueTest extends \PHPUnit\Framework\TestCase
1919
*/
2020
private $model;
2121

22+
/**
23+
* @var \Magento\Catalog\Pricing\Price\CustomOptionPriceCalculator
24+
*/
25+
private $customOptionPriceCalculatorMock;
26+
27+
protected function setUp()
28+
{
29+
$mockedResource = $this->getMockedResource();
30+
$mockedCollectionFactory = $this->getMockedValueCollectionFactory();
31+
32+
$this->customOptionPriceCalculatorMock = $this->createMock(
33+
\Magento\Catalog\Pricing\Price\CustomOptionPriceCalculator::class
34+
);
35+
36+
$helper = new ObjectManager($this);
37+
$this->model = $helper->getObject(
38+
\Magento\Catalog\Model\Product\Option\Value::class,
39+
[
40+
'resource' => $mockedResource,
41+
'valueCollectionFactory' => $mockedCollectionFactory,
42+
'customOptionPriceCalculator' => $this->customOptionPriceCalculatorMock,
43+
]
44+
);
45+
$this->model->setOption($this->getMockedOption());
46+
}
47+
2248
public function testSaveProduct()
2349
{
2450
$this->model->setValues([100])
@@ -35,11 +61,16 @@ public function testSaveProduct()
3561

3662
public function testGetPrice()
3763
{
38-
$this->model->setPrice(1000);
64+
$price = 1000;
65+
$this->model->setPrice($price);
3966
$this->model->setPriceType(Value::TYPE_PERCENT);
40-
$this->assertEquals(1000, $this->model->getPrice(false));
67+
$this->assertEquals($price, $this->model->getPrice(false));
4168

42-
$this->assertEquals(100, $this->model->getPrice(true));
69+
$percentPice = 100;
70+
$this->customOptionPriceCalculatorMock->expects($this->atLeastOnce())
71+
->method('getOptionPriceByPriceCode')
72+
->willReturn($percentPice);
73+
$this->assertEquals($percentPice, $this->model->getPrice(true));
4374
}
4475

4576
public function testGetValuesCollection()
@@ -78,23 +109,6 @@ public function testDeleteValue()
78109
$this->assertInstanceOf(\Magento\Catalog\Model\Product\Option\Value::class, $this->model->deleteValue(1));
79110
}
80111

81-
protected function setUp()
82-
{
83-
$mockedResource = $this->getMockedResource();
84-
$mockedCollectionFactory = $this->getMockedValueCollectionFactory();
85-
$mockedContext = $this->getMockedContext();
86-
$helper = new ObjectManager($this);
87-
$this->model = $helper->getObject(
88-
\Magento\Catalog\Model\Product\Option\Value::class,
89-
[
90-
'resource' => $mockedResource,
91-
'valueCollectionFactory' => $mockedCollectionFactory,
92-
'context' => $mockedContext
93-
]
94-
);
95-
$this->model->setOption($this->getMockedOption());
96-
}
97-
98112
/**
99113
* @return \Magento\Catalog\Model\ResourceModel\Product\Option\Value\CollectionFactory
100114
*/
@@ -243,61 +257,4 @@ private function getMockedResource()
243257

244258
return $mock;
245259
}
246-
247-
/**
248-
* @return \Magento\Framework\Model\Context
249-
*/
250-
private function getMockedContext()
251-
{
252-
$mockedRemoveAction = $this->getMockedRemoveAction();
253-
$mockEventManager = $this->getMockedEventManager();
254-
255-
$mockBuilder = $this->getMockBuilder(\Magento\Framework\Model\Context::class)
256-
->setMethods(['getActionValidator', 'getEventDispatcher'])
257-
->disableOriginalConstructor();
258-
$mock = $mockBuilder->getMock();
259-
260-
$mock->expects($this->any())
261-
->method('getActionValidator')
262-
->will($this->returnValue($mockedRemoveAction));
263-
264-
$mock->expects($this->any())
265-
->method('getEventDispatcher')
266-
->will($this->returnValue($mockEventManager));
267-
268-
return $mock;
269-
}
270-
271-
/**
272-
* @return RemoveAction
273-
*/
274-
private function getMockedRemoveAction()
275-
{
276-
$mockBuilder = $this->getMockBuilder(\Magento\Framework\Model\Context::class)
277-
->setMethods(['isAllowed'])
278-
->disableOriginalConstructor();
279-
$mock = $mockBuilder->getMock();
280-
281-
$mock->expects($this->any())
282-
->method('isAllowed')
283-
->will($this->returnValue(true));
284-
285-
return $mock;
286-
}
287-
288-
/**
289-
* @return \Magento\Framework\Event\ManagerInterface
290-
*/
291-
private function getMockedEventManager()
292-
{
293-
$mockBuilder = $this->getMockBuilder(\Magento\Framework\Event\ManagerInterface::class)
294-
->setMethods(['dispatch'])
295-
->disableOriginalConstructor();
296-
$mock = $mockBuilder->getMockForAbstractClass();
297-
298-
$mock->expects($this->any())
299-
->method('dispatch');
300-
301-
return $mock;
302-
}
303260
}

app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,20 @@ public function testGetFinalPricePreset()
13931393
$qty = 1;
13941394
$this->model->setQty($qty);
13951395
$this->model->setFinalPrice($finalPrice);
1396-
$this->productTypeInstanceMock->expects($this->never())->method('priceFactory');
1396+
$productTypePriceMock = $this->createPartialMock(
1397+
\Magento\Catalog\Model\Product\Type\Price::class,
1398+
['getFinalPrice']
1399+
);
1400+
$productTypePriceMock->expects($this->any())
1401+
->method('getFinalPrice')
1402+
->with($qty, $this->model)
1403+
->will($this->returnValue($finalPrice));
1404+
1405+
$this->productTypeInstanceMock->expects($this->any())
1406+
->method('priceFactory')
1407+
->with($this->model->getTypeId())
1408+
->will($this->returnValue($productTypePriceMock));
1409+
13971410
$this->assertEquals($finalPrice, $this->model->getFinalPrice($qty));
13981411
}
13991412

0 commit comments

Comments
 (0)