Skip to content

Commit

Permalink
Merge branch 'develop' of github.corp.magento.com:magento2/magento2ce…
Browse files Browse the repository at this point in the history
… into MAGETWO-52170
  • Loading branch information
valdislav committed May 6, 2016
2 parents 0c5880a + efc35bb commit 04366d2
Show file tree
Hide file tree
Showing 47 changed files with 1,184 additions and 316 deletions.
10 changes: 4 additions & 6 deletions app/code/Magento/Bundle/Pricing/Price/BundleRegularPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,20 @@ public function __construct(
}

/**
* Get Price Amount object
*
* @return AmountInterface
* @inheritdoc
*/
public function getAmount()
{
if (null === $this->amount) {
if (!isset($this->amount[$this->getValue()])) {
$price = $this->getValue();
if ($this->product->getPriceType() == Price::PRICE_TYPE_FIXED) {
/** @var \Magento\Catalog\Pricing\Price\CustomOptionPrice $customOptionPrice */
$customOptionPrice = $this->priceInfo->getPrice(CustomOptionPrice::PRICE_CODE);
$price += $customOptionPrice->getCustomOptionRange(true);
}
$this->amount = $this->calculator->getMinRegularAmount($price, $this->product);
$this->amount[$this->getValue()] = $this->calculator->getMinRegularAmount($price, $this->product);
}
return $this->amount;
return $this->amount[$this->getValue()];
}

/**
Expand Down
10 changes: 7 additions & 3 deletions app/code/Magento/Bundle/Pricing/Price/BundleSelectionPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,18 @@ public function getValue()
*/
public function getAmount()
{
if (null === $this->amount) {
if (!isset($this->amount[$this->getValue()])) {
$exclude = null;
if ($this->getProduct()->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
$exclude = $this->excludeAdjustment;
}
$this->amount = $this->calculator->getAmount($this->getValue(), $this->getProduct(), $exclude);
$this->amount[$this->getValue()] = $this->calculator->getAmount(
$this->getValue(),
$this->getProduct(),
$exclude
);
}
return $this->amount;
return $this->amount[$this->getValue()];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,8 @@ protected function setUp()
'',
false
);
$this->calculatorMock = $this->getMock(
'Magento\Framework\Pricing\Adjustment\CalculatorInterface',
[],
[],
'',
false,
true,
false
);
$this->calculatorMock = $this->getMockBuilder('Magento\Framework\Pricing\Adjustment\CalculatorInterface')
->getMockForAbstractClass();
$this->eventManagerMock = $this->getMock(
'Magento\Framework\Event\Manager',
['dispatch'],
Expand Down Expand Up @@ -349,4 +342,42 @@ public function testGetProductDynamicBundle()
$product = $this->selectionPrice->getProduct();
$this->assertEquals($this->productMock, $product);
}

public function testGetAmount()
{
$this->setupSelectionPrice();

$price = 10.;
$amount = 20.;

$this->priceInfoMock->expects($this->once())
->method('getPrice')
->with(\Magento\Bundle\Pricing\Price\FinalPrice::PRICE_CODE)
->willReturn($this->finalPriceMock);

$this->finalPriceMock->expects($this->once())
->method('getValue')
->willReturn($price);

$this->discountCalculatorMock->expects($this->once())
->method('calculateDiscount')
->with($this->bundleMock, $price)
->willReturn($price);

$this->priceCurrencyMock->expects($this->once())
->method('round')
->with($price)
->willReturn($price);

$this->bundleMock->expects($this->any())
->method('getPriceType')
->willReturn(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC);

$this->calculatorMock->expects($this->once())
->method('getAmount')
->with($price, $this->productMock, null)
->willReturn($amount);

$this->assertEquals($amount, $this->selectionPrice->getAmount());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ public function __construct(
* Reindex single row by id
*
* @param int $id
* @param bool $forceReindex
* @return void
*/
public function reindexRow($id)
public function reindexRow($id, $forceReindex = false)
{
if (!$this->_state->isFlatEnabled() || $this->getIndexer()->isScheduled()) {
if (!$this->_state->isFlatEnabled() || (!$forceReindex && $this->getIndexer()->isScheduled())) {
return;
}
$this->getIndexer()->reindexRow($id);
Expand All @@ -47,11 +48,12 @@ public function reindexRow($id)
* Reindex multiple rows by ids
*
* @param int[] $ids
* @param bool $forceReindex
* @return void
*/
public function reindexList($ids)
public function reindexList($ids, $forceReindex = false)
{
if (!$this->_state->isFlatEnabled() || $this->getIndexer()->isScheduled()) {
if (!$this->_state->isFlatEnabled() || (!$forceReindex && $this->getIndexer()->isScheduled())) {
return;
}
$this->getIndexer()->reindexList($ids);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Catalog\Test\Unit\Model\Indexer\Product\Flat;

use Magento\Catalog\Model\Indexer\Product\Flat\Processor;

class ProcessorTest extends \PHPUnit_Framework_TestCase
{
/**
Expand All @@ -13,7 +15,7 @@ class ProcessorTest extends \PHPUnit_Framework_TestCase
protected $_objectManager;

/**
* @var \Magento\Catalog\Model\Indexer\Product\Flat\Processor
* @var Processor
*/
protected $_model;

Expand Down Expand Up @@ -99,7 +101,145 @@ protected function prepareIndexer()
{
$this->indexerRegistryMock->expects($this->once())
->method('get')
->with(\Magento\Catalog\Model\Indexer\Product\Flat\Processor::INDEXER_ID)
->with(Processor::INDEXER_ID)
->will($this->returnValue($this->_indexerMock));
}

/**
* @param bool $isFlatEnabled
* @param bool $forceReindex
* @param bool $isScheduled
* @dataProvider dataProviderReindexRow
*/
public function testReindexRow(
$isFlatEnabled,
$forceReindex,
$isScheduled
) {
$this->_stateMock->expects($this->once())
->method('isFlatEnabled')
->willReturn($isFlatEnabled);

$indexerMock = $this->getMockBuilder('Magento\Indexer\Model\Indexer')
->disableOriginalConstructor()
->getMock();

$this->indexerRegistryMock->expects($this->any())
->method('get')
->with(Processor::INDEXER_ID)
->willReturn($indexerMock);

$indexerMock->expects($this->any())
->method('isScheduled')
->willReturn($isScheduled);
$indexerMock->expects($this->never())
->method('reindexRow');

$this->_model->reindexRow(1, $forceReindex);
}

public function dataProviderReindexRow()
{
return [
[false, false, null],
[true, false, true],
];
}

public function testReindexRowForce()
{
$id = 1;

$this->_stateMock->expects($this->once())
->method('isFlatEnabled')
->willReturn(true);

$indexerMock = $this->getMockBuilder('Magento\Indexer\Model\Indexer')
->disableOriginalConstructor()
->getMock();

$this->indexerRegistryMock->expects($this->any())
->method('get')
->with(Processor::INDEXER_ID)
->willReturn($indexerMock);

$indexerMock->expects($this->any())
->method('isScheduled')
->willReturn(true);
$indexerMock->expects($this->any())
->method('reindexList')
->with($id)
->willReturnSelf();

$this->_model->reindexRow($id, true);
}

/**
* @param bool $isFlatEnabled
* @param bool $forceReindex
* @param bool $isScheduled
* @dataProvider dataProviderReindexList
*/
public function testReindexList(
$isFlatEnabled,
$forceReindex,
$isScheduled
) {
$this->_stateMock->expects($this->once())
->method('isFlatEnabled')
->willReturn($isFlatEnabled);

$indexerMock = $this->getMockBuilder('Magento\Indexer\Model\Indexer')
->disableOriginalConstructor()
->getMock();

$this->indexerRegistryMock->expects($this->any())
->method('get')
->with(Processor::INDEXER_ID)
->willReturn($indexerMock);

$indexerMock->expects($this->any())
->method('isScheduled')
->willReturn($isScheduled);
$indexerMock->expects($this->never())
->method('reindexList');

$this->_model->reindexList([1], $forceReindex);
}

public function dataProviderReindexList()
{
return [
[false, false, null],
[true, false, true],
];
}

public function testReindexListForce()
{
$ids = [1];

$this->_stateMock->expects($this->once())
->method('isFlatEnabled')
->willReturn(true);

$indexerMock = $this->getMockBuilder('Magento\Indexer\Model\Indexer')
->disableOriginalConstructor()
->getMock();

$this->indexerRegistryMock->expects($this->any())
->method('get')
->with(Processor::INDEXER_ID)
->willReturn($indexerMock);

$indexerMock->expects($this->any())
->method('isScheduled')
->willReturn(true);
$indexerMock->expects($this->any())
->method('reindexList')
->with($ids)
->willReturnSelf();

$this->_model->reindexList($ids, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BasePriceTest extends \PHPUnit_Framework_TestCase
protected $saleableItemMock;

/**
* @var \Magento\Framework\Pricing\Adjustment\Calculator
* @var \Magento\Framework\Pricing\Adjustment\Calculator|\PHPUnit_Framework_MockObject_MockObject
*/
protected $calculatorMock;

Expand Down Expand Up @@ -111,4 +111,23 @@ public function getValueDataProvider()
{
return [[77, 77], [0, 0], [false, 99]];
}

public function testGetAmount()
{
$amount = 20.;

$priceMock = $this->getMockBuilder('Magento\Framework\Pricing\Price\PriceInterface')
->getMockForAbstractClass();

$this->priceInfoMock->expects($this->once())
->method('getPrices')
->willReturn([$priceMock]);

$this->calculatorMock->expects($this->once())
->method('getAmount')
->with(false, $this->saleableItemMock)
->willReturn($amount);

$this->assertEquals($amount, $this->basePrice->getAmount());
}
}
Loading

0 comments on commit 04366d2

Please sign in to comment.