|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2016 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\ConfigurableProduct\Test\Unit\Pricing\Render; |
| 7 | + |
| 8 | +use Magento\Catalog\Pricing\Price\FinalPrice; |
| 9 | +use Magento\Catalog\Pricing\Price\RegularPrice; |
| 10 | +use Magento\ConfigurableProduct\Pricing\Price\ConfigurableOptionsProviderInterface; |
| 11 | +use Magento\ConfigurableProduct\Pricing\Render\FinalPriceBox; |
| 12 | + |
| 13 | +class FinalPriceBoxTest extends \PHPUnit_Framework_TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @var \Magento\Framework\View\Element\Template\Context|\PHPUnit_Framework_MockObject_MockObject |
| 17 | + */ |
| 18 | + private $context; |
| 19 | + |
| 20 | + /** |
| 21 | + * @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject |
| 22 | + */ |
| 23 | + private $saleableItem; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var \Magento\Framework\Pricing\Price\PriceInterface|\PHPUnit_Framework_MockObject_MockObject |
| 27 | + */ |
| 28 | + private $price; |
| 29 | + |
| 30 | + /** |
| 31 | + * @var \Magento\Framework\Pricing\Render\RendererPool|\PHPUnit_Framework_MockObject_MockObject |
| 32 | + */ |
| 33 | + private $rendererPool; |
| 34 | + |
| 35 | + /** |
| 36 | + * @var ConfigurableOptionsProviderInterface|\PHPUnit_Framework_MockObject_MockObject |
| 37 | + */ |
| 38 | + private $configurableOptionsProvider; |
| 39 | + |
| 40 | + /** |
| 41 | + * @var FinalPriceBox |
| 42 | + */ |
| 43 | + private $model; |
| 44 | + |
| 45 | + protected function setUp() |
| 46 | + { |
| 47 | + $this->context = $this->getMockBuilder(\Magento\Framework\View\Element\Template\Context::class) |
| 48 | + ->disableOriginalConstructor() |
| 49 | + ->getMock(); |
| 50 | + |
| 51 | + $this->saleableItem = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) |
| 52 | + ->disableOriginalConstructor() |
| 53 | + ->getMock(); |
| 54 | + |
| 55 | + $this->price = $this->getMockBuilder(\Magento\Framework\Pricing\Price\PriceInterface::class) |
| 56 | + ->getMockForAbstractClass(); |
| 57 | + |
| 58 | + $this->rendererPool = $this->getMockBuilder(\Magento\Framework\Pricing\Render\RendererPool::class) |
| 59 | + ->disableOriginalConstructor() |
| 60 | + ->getMock(); |
| 61 | + |
| 62 | + $this->configurableOptionsProvider = $this->getMockBuilder(ConfigurableOptionsProviderInterface::class) |
| 63 | + ->getMockForAbstractClass(); |
| 64 | + |
| 65 | + $this->model = new FinalPriceBox( |
| 66 | + $this->context, |
| 67 | + $this->saleableItem, |
| 68 | + $this->price, |
| 69 | + $this->rendererPool, |
| 70 | + $this->configurableOptionsProvider |
| 71 | + ); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * @param float $regularPrice |
| 76 | + * @param float $finalPrice |
| 77 | + * @param bool $expected |
| 78 | + * @dataProvider DataProviderHasSpecialPrice |
| 79 | + */ |
| 80 | + public function testHasSpecialPrice( |
| 81 | + $regularPrice, |
| 82 | + $finalPrice, |
| 83 | + $expected |
| 84 | + ) { |
| 85 | + $priceMockOne = $this->getMockBuilder(\Magento\Framework\Pricing\Price\PriceInterface::class) |
| 86 | + ->getMockForAbstractClass(); |
| 87 | + |
| 88 | + $priceMockOne->expects($this->once()) |
| 89 | + ->method('getValue') |
| 90 | + ->willReturn($regularPrice); |
| 91 | + |
| 92 | + $priceMockTwo = $this->getMockBuilder(\Magento\Framework\Pricing\Price\PriceInterface::class) |
| 93 | + ->getMockForAbstractClass(); |
| 94 | + |
| 95 | + $priceMockTwo->expects($this->once()) |
| 96 | + ->method('getValue') |
| 97 | + ->willReturn($finalPrice); |
| 98 | + |
| 99 | + $priceInfoMock = $this->getMockBuilder(\Magento\Framework\Pricing\PriceInfo\Base::class) |
| 100 | + ->disableOriginalConstructor() |
| 101 | + ->getMock(); |
| 102 | + |
| 103 | + $priceInfoMock->expects($this->exactly(2)) |
| 104 | + ->method('getPrice') |
| 105 | + ->willReturnMap([ |
| 106 | + [RegularPrice::PRICE_CODE, $priceMockOne], |
| 107 | + [FinalPrice::PRICE_CODE, $priceMockTwo], |
| 108 | + ]); |
| 109 | + |
| 110 | + $productMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class) |
| 111 | + ->setMethods(['getPriceInfo']) |
| 112 | + ->getMockForAbstractClass(); |
| 113 | + |
| 114 | + $productMock->expects($this->exactly(2)) |
| 115 | + ->method('getPriceInfo') |
| 116 | + ->willReturn($priceInfoMock); |
| 117 | + |
| 118 | + $this->configurableOptionsProvider->expects($this->once()) |
| 119 | + ->method('getProducts') |
| 120 | + ->with($this->saleableItem) |
| 121 | + ->willReturn([$productMock]); |
| 122 | + |
| 123 | + $this->assertEquals($expected, $this->model->hasSpecialPrice()); |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * @return array |
| 128 | + */ |
| 129 | + public function DataProviderHasSpecialPrice() |
| 130 | + { |
| 131 | + return [ |
| 132 | + [10., 20., false], |
| 133 | + [10., 10., false], |
| 134 | + [20., 10., true], |
| 135 | + ]; |
| 136 | + } |
| 137 | +} |
0 commit comments