Skip to content

Commit

Permalink
MAGETWO-52925: Simple child product without a special price still sho…
Browse files Browse the repository at this point in the history
…wn as "was (original price)" #4442 #5097
  • Loading branch information
Sergey Semenov committed Aug 30, 2016
1 parent 10fc55c commit 73dfa14
Showing 1 changed file with 137 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\ConfigurableProduct\Test\Unit\Pricing\Render;

use Magento\Catalog\Pricing\Price\FinalPrice;
use Magento\Catalog\Pricing\Price\RegularPrice;
use Magento\ConfigurableProduct\Pricing\Price\ConfigurableOptionsProviderInterface;
use Magento\ConfigurableProduct\Pricing\Render\FinalPriceBox;

class FinalPriceBoxTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Framework\View\Element\Template\Context|\PHPUnit_Framework_MockObject_MockObject
*/
private $context;

/**
* @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject
*/
private $saleableItem;

/**
* @var \Magento\Framework\Pricing\Price\PriceInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $price;

/**
* @var \Magento\Framework\Pricing\Render\RendererPool|\PHPUnit_Framework_MockObject_MockObject
*/
private $rendererPool;

/**
* @var ConfigurableOptionsProviderInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $configurableOptionsProvider;

/**
* @var FinalPriceBox
*/
private $model;

protected function setUp()
{
$this->context = $this->getMockBuilder(\Magento\Framework\View\Element\Template\Context::class)
->disableOriginalConstructor()
->getMock();

$this->saleableItem = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
->disableOriginalConstructor()
->getMock();

$this->price = $this->getMockBuilder(\Magento\Framework\Pricing\Price\PriceInterface::class)
->getMockForAbstractClass();

$this->rendererPool = $this->getMockBuilder(\Magento\Framework\Pricing\Render\RendererPool::class)
->disableOriginalConstructor()
->getMock();

$this->configurableOptionsProvider = $this->getMockBuilder(ConfigurableOptionsProviderInterface::class)
->getMockForAbstractClass();

$this->model = new FinalPriceBox(
$this->context,
$this->saleableItem,
$this->price,
$this->rendererPool,
$this->configurableOptionsProvider
);
}

/**
* @param float $regularPrice
* @param float $finalPrice
* @param bool $expected
* @dataProvider DataProviderHasSpecialPrice
*/
public function testHasSpecialPrice(
$regularPrice,
$finalPrice,
$expected
) {
$priceMockOne = $this->getMockBuilder(\Magento\Framework\Pricing\Price\PriceInterface::class)
->getMockForAbstractClass();

$priceMockOne->expects($this->once())
->method('getValue')
->willReturn($regularPrice);

$priceMockTwo = $this->getMockBuilder(\Magento\Framework\Pricing\Price\PriceInterface::class)
->getMockForAbstractClass();

$priceMockTwo->expects($this->once())
->method('getValue')
->willReturn($finalPrice);

$priceInfoMock = $this->getMockBuilder(\Magento\Framework\Pricing\PriceInfo\Base::class)
->disableOriginalConstructor()
->getMock();

$priceInfoMock->expects($this->exactly(2))
->method('getPrice')
->willReturnMap([
[RegularPrice::PRICE_CODE, $priceMockOne],
[FinalPrice::PRICE_CODE, $priceMockTwo],
]);

$productMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class)
->setMethods(['getPriceInfo'])
->getMockForAbstractClass();

$productMock->expects($this->exactly(2))
->method('getPriceInfo')
->willReturn($priceInfoMock);

$this->configurableOptionsProvider->expects($this->once())
->method('getProducts')
->with($this->saleableItem)
->willReturn([$productMock]);

$this->assertEquals($expected, $this->model->hasSpecialPrice());
}

/**
* @return array
*/
public function DataProviderHasSpecialPrice()
{
return [
[10., 20., false],
[10., 10., false],
[20., 10., true],
];
}
}

0 comments on commit 73dfa14

Please sign in to comment.