-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAGETWO-52925: Simple child product without a special price still sho…
- Loading branch information
Sergey Semenov
committed
Aug 30, 2016
1 parent
10fc55c
commit 73dfa14
Showing
1 changed file
with
137 additions
and
0 deletions.
There are no files selected for viewing
137 changes: 137 additions & 0 deletions
137
app/code/Magento/ConfigurableProduct/Test/Unit/Pricing/Render/FinalPriceBoxTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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], | ||
]; | ||
} | ||
} |