Skip to content

Commit 04366d2

Browse files
committed
Merge branch 'develop' of github.corp.magento.com:magento2/magento2ce into MAGETWO-52170
2 parents 0c5880a + efc35bb commit 04366d2

File tree

47 files changed

+1184
-316
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1184
-316
lines changed

app/code/Magento/Bundle/Pricing/Price/BundleRegularPrice.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,20 @@ public function __construct(
4343
}
4444

4545
/**
46-
* Get Price Amount object
47-
*
48-
* @return AmountInterface
46+
* @inheritdoc
4947
*/
5048
public function getAmount()
5149
{
52-
if (null === $this->amount) {
50+
if (!isset($this->amount[$this->getValue()])) {
5351
$price = $this->getValue();
5452
if ($this->product->getPriceType() == Price::PRICE_TYPE_FIXED) {
5553
/** @var \Magento\Catalog\Pricing\Price\CustomOptionPrice $customOptionPrice */
5654
$customOptionPrice = $this->priceInfo->getPrice(CustomOptionPrice::PRICE_CODE);
5755
$price += $customOptionPrice->getCustomOptionRange(true);
5856
}
59-
$this->amount = $this->calculator->getMinRegularAmount($price, $this->product);
57+
$this->amount[$this->getValue()] = $this->calculator->getMinRegularAmount($price, $this->product);
6058
}
61-
return $this->amount;
59+
return $this->amount[$this->getValue()];
6260
}
6361

6462
/**

app/code/Magento/Bundle/Pricing/Price/BundleSelectionPrice.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,18 @@ public function getValue()
142142
*/
143143
public function getAmount()
144144
{
145-
if (null === $this->amount) {
145+
if (!isset($this->amount[$this->getValue()])) {
146146
$exclude = null;
147147
if ($this->getProduct()->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
148148
$exclude = $this->excludeAdjustment;
149149
}
150-
$this->amount = $this->calculator->getAmount($this->getValue(), $this->getProduct(), $exclude);
150+
$this->amount[$this->getValue()] = $this->calculator->getAmount(
151+
$this->getValue(),
152+
$this->getProduct(),
153+
$exclude
154+
);
151155
}
152-
return $this->amount;
156+
return $this->amount[$this->getValue()];
153157
}
154158

155159
/**

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

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,8 @@ protected function setUp()
9191
'',
9292
false
9393
);
94-
$this->calculatorMock = $this->getMock(
95-
'Magento\Framework\Pricing\Adjustment\CalculatorInterface',
96-
[],
97-
[],
98-
'',
99-
false,
100-
true,
101-
false
102-
);
94+
$this->calculatorMock = $this->getMockBuilder('Magento\Framework\Pricing\Adjustment\CalculatorInterface')
95+
->getMockForAbstractClass();
10396
$this->eventManagerMock = $this->getMock(
10497
'Magento\Framework\Event\Manager',
10598
['dispatch'],
@@ -349,4 +342,42 @@ public function testGetProductDynamicBundle()
349342
$product = $this->selectionPrice->getProduct();
350343
$this->assertEquals($this->productMock, $product);
351344
}
345+
346+
public function testGetAmount()
347+
{
348+
$this->setupSelectionPrice();
349+
350+
$price = 10.;
351+
$amount = 20.;
352+
353+
$this->priceInfoMock->expects($this->once())
354+
->method('getPrice')
355+
->with(\Magento\Bundle\Pricing\Price\FinalPrice::PRICE_CODE)
356+
->willReturn($this->finalPriceMock);
357+
358+
$this->finalPriceMock->expects($this->once())
359+
->method('getValue')
360+
->willReturn($price);
361+
362+
$this->discountCalculatorMock->expects($this->once())
363+
->method('calculateDiscount')
364+
->with($this->bundleMock, $price)
365+
->willReturn($price);
366+
367+
$this->priceCurrencyMock->expects($this->once())
368+
->method('round')
369+
->with($price)
370+
->willReturn($price);
371+
372+
$this->bundleMock->expects($this->any())
373+
->method('getPriceType')
374+
->willReturn(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC);
375+
376+
$this->calculatorMock->expects($this->once())
377+
->method('getAmount')
378+
->with($price, $this->productMock, null)
379+
->willReturn($amount);
380+
381+
$this->assertEquals($amount, $this->selectionPrice->getAmount());
382+
}
352383
}

app/code/Magento/Catalog/Model/Indexer/Product/Flat/Processor.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ public function __construct(
3333
* Reindex single row by id
3434
*
3535
* @param int $id
36+
* @param bool $forceReindex
3637
* @return void
3738
*/
38-
public function reindexRow($id)
39+
public function reindexRow($id, $forceReindex = false)
3940
{
40-
if (!$this->_state->isFlatEnabled() || $this->getIndexer()->isScheduled()) {
41+
if (!$this->_state->isFlatEnabled() || (!$forceReindex && $this->getIndexer()->isScheduled())) {
4142
return;
4243
}
4344
$this->getIndexer()->reindexRow($id);
@@ -47,11 +48,12 @@ public function reindexRow($id)
4748
* Reindex multiple rows by ids
4849
*
4950
* @param int[] $ids
51+
* @param bool $forceReindex
5052
* @return void
5153
*/
52-
public function reindexList($ids)
54+
public function reindexList($ids, $forceReindex = false)
5355
{
54-
if (!$this->_state->isFlatEnabled() || $this->getIndexer()->isScheduled()) {
56+
if (!$this->_state->isFlatEnabled() || (!$forceReindex && $this->getIndexer()->isScheduled())) {
5557
return;
5658
}
5759
$this->getIndexer()->reindexList($ids);

app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Flat/ProcessorTest.php

Lines changed: 142 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Catalog\Test\Unit\Model\Indexer\Product\Flat;
77

8+
use Magento\Catalog\Model\Indexer\Product\Flat\Processor;
9+
810
class ProcessorTest extends \PHPUnit_Framework_TestCase
911
{
1012
/**
@@ -13,7 +15,7 @@ class ProcessorTest extends \PHPUnit_Framework_TestCase
1315
protected $_objectManager;
1416

1517
/**
16-
* @var \Magento\Catalog\Model\Indexer\Product\Flat\Processor
18+
* @var Processor
1719
*/
1820
protected $_model;
1921

@@ -99,7 +101,145 @@ protected function prepareIndexer()
99101
{
100102
$this->indexerRegistryMock->expects($this->once())
101103
->method('get')
102-
->with(\Magento\Catalog\Model\Indexer\Product\Flat\Processor::INDEXER_ID)
104+
->with(Processor::INDEXER_ID)
103105
->will($this->returnValue($this->_indexerMock));
104106
}
107+
108+
/**
109+
* @param bool $isFlatEnabled
110+
* @param bool $forceReindex
111+
* @param bool $isScheduled
112+
* @dataProvider dataProviderReindexRow
113+
*/
114+
public function testReindexRow(
115+
$isFlatEnabled,
116+
$forceReindex,
117+
$isScheduled
118+
) {
119+
$this->_stateMock->expects($this->once())
120+
->method('isFlatEnabled')
121+
->willReturn($isFlatEnabled);
122+
123+
$indexerMock = $this->getMockBuilder('Magento\Indexer\Model\Indexer')
124+
->disableOriginalConstructor()
125+
->getMock();
126+
127+
$this->indexerRegistryMock->expects($this->any())
128+
->method('get')
129+
->with(Processor::INDEXER_ID)
130+
->willReturn($indexerMock);
131+
132+
$indexerMock->expects($this->any())
133+
->method('isScheduled')
134+
->willReturn($isScheduled);
135+
$indexerMock->expects($this->never())
136+
->method('reindexRow');
137+
138+
$this->_model->reindexRow(1, $forceReindex);
139+
}
140+
141+
public function dataProviderReindexRow()
142+
{
143+
return [
144+
[false, false, null],
145+
[true, false, true],
146+
];
147+
}
148+
149+
public function testReindexRowForce()
150+
{
151+
$id = 1;
152+
153+
$this->_stateMock->expects($this->once())
154+
->method('isFlatEnabled')
155+
->willReturn(true);
156+
157+
$indexerMock = $this->getMockBuilder('Magento\Indexer\Model\Indexer')
158+
->disableOriginalConstructor()
159+
->getMock();
160+
161+
$this->indexerRegistryMock->expects($this->any())
162+
->method('get')
163+
->with(Processor::INDEXER_ID)
164+
->willReturn($indexerMock);
165+
166+
$indexerMock->expects($this->any())
167+
->method('isScheduled')
168+
->willReturn(true);
169+
$indexerMock->expects($this->any())
170+
->method('reindexList')
171+
->with($id)
172+
->willReturnSelf();
173+
174+
$this->_model->reindexRow($id, true);
175+
}
176+
177+
/**
178+
* @param bool $isFlatEnabled
179+
* @param bool $forceReindex
180+
* @param bool $isScheduled
181+
* @dataProvider dataProviderReindexList
182+
*/
183+
public function testReindexList(
184+
$isFlatEnabled,
185+
$forceReindex,
186+
$isScheduled
187+
) {
188+
$this->_stateMock->expects($this->once())
189+
->method('isFlatEnabled')
190+
->willReturn($isFlatEnabled);
191+
192+
$indexerMock = $this->getMockBuilder('Magento\Indexer\Model\Indexer')
193+
->disableOriginalConstructor()
194+
->getMock();
195+
196+
$this->indexerRegistryMock->expects($this->any())
197+
->method('get')
198+
->with(Processor::INDEXER_ID)
199+
->willReturn($indexerMock);
200+
201+
$indexerMock->expects($this->any())
202+
->method('isScheduled')
203+
->willReturn($isScheduled);
204+
$indexerMock->expects($this->never())
205+
->method('reindexList');
206+
207+
$this->_model->reindexList([1], $forceReindex);
208+
}
209+
210+
public function dataProviderReindexList()
211+
{
212+
return [
213+
[false, false, null],
214+
[true, false, true],
215+
];
216+
}
217+
218+
public function testReindexListForce()
219+
{
220+
$ids = [1];
221+
222+
$this->_stateMock->expects($this->once())
223+
->method('isFlatEnabled')
224+
->willReturn(true);
225+
226+
$indexerMock = $this->getMockBuilder('Magento\Indexer\Model\Indexer')
227+
->disableOriginalConstructor()
228+
->getMock();
229+
230+
$this->indexerRegistryMock->expects($this->any())
231+
->method('get')
232+
->with(Processor::INDEXER_ID)
233+
->willReturn($indexerMock);
234+
235+
$indexerMock->expects($this->any())
236+
->method('isScheduled')
237+
->willReturn(true);
238+
$indexerMock->expects($this->any())
239+
->method('reindexList')
240+
->with($ids)
241+
->willReturnSelf();
242+
243+
$this->_model->reindexList($ids, true);
244+
}
105245
}

app/code/Magento/Catalog/Test/Unit/Pricing/Price/BasePriceTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class BasePriceTest extends \PHPUnit_Framework_TestCase
2929
protected $saleableItemMock;
3030

3131
/**
32-
* @var \Magento\Framework\Pricing\Adjustment\Calculator
32+
* @var \Magento\Framework\Pricing\Adjustment\Calculator|\PHPUnit_Framework_MockObject_MockObject
3333
*/
3434
protected $calculatorMock;
3535

@@ -111,4 +111,23 @@ public function getValueDataProvider()
111111
{
112112
return [[77, 77], [0, 0], [false, 99]];
113113
}
114+
115+
public function testGetAmount()
116+
{
117+
$amount = 20.;
118+
119+
$priceMock = $this->getMockBuilder('Magento\Framework\Pricing\Price\PriceInterface')
120+
->getMockForAbstractClass();
121+
122+
$this->priceInfoMock->expects($this->once())
123+
->method('getPrices')
124+
->willReturn([$priceMock]);
125+
126+
$this->calculatorMock->expects($this->once())
127+
->method('getAmount')
128+
->with(false, $this->saleableItemMock)
129+
->willReturn($amount);
130+
131+
$this->assertEquals($amount, $this->basePrice->getAmount());
132+
}
114133
}

0 commit comments

Comments
 (0)