|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2013-2017 Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\ConfigurableProduct\Test\Unit\Pricing\Render; |
| 8 | +use Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolverInterface; |
| 9 | +use Magento\ConfigurableProduct\Pricing\Price\ConfigurableOptionsProviderInterface; |
| 10 | +use Magento\ConfigurableProduct\Pricing\Price\LowestPriceOptionsProviderInterface; |
| 11 | +use Magento\Framework\ObjectManagerInterface; |
| 12 | + |
| 13 | +/** |
| 14 | + * Tests \Magento\ConfigurableProduct\Pricing\Render\TierPriceBox |
| 15 | + */ |
| 16 | +class TierPriceBoxTest extends \PHPUnit_Framework_TestCase |
| 17 | +{ |
| 18 | + /** @var \Magento\ConfigurableProduct\Pricing\Render\TierPriceBox */ |
| 19 | + private $priceBox; |
| 20 | + |
| 21 | + /** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */ |
| 22 | + private $objectManager; |
| 23 | + |
| 24 | + /** @var \Magento\Framework\View\Element\Template\Context||\PHPUnit_Framework_MockObject_MockObject */ |
| 25 | + private $contextMock; |
| 26 | + |
| 27 | + /** @var \Magento\Catalog\Model\Product||\PHPUnit_Framework_MockObject_MockObject */ |
| 28 | + private $saleableItemMock; |
| 29 | + |
| 30 | + /** @var \Magento\Framework\Pricing\Price\PriceInterface||\PHPUnit_Framework_MockObject_MockObject */ |
| 31 | + private $priceMock; |
| 32 | + |
| 33 | + /** @var \Magento\Framework\Pricing\Render\RendererPool||\PHPUnit_Framework_MockObject_MockObject */ |
| 34 | + private $rendererPoolMock; |
| 35 | + |
| 36 | + /** @var ConfigurableOptionsProviderInterface||\PHPUnit_Framework_MockObject_MockObject */ |
| 37 | + private $configurableOptionsProviderMock; |
| 38 | + |
| 39 | + /** @var LowestPriceOptionsProviderInterface||\PHPUnit_Framework_MockObject_MockObject */ |
| 40 | + private $lowestPriceOptionsProviderMock; |
| 41 | + |
| 42 | + /** @var \Magento\Framework\Module\Manager|\PHPUnit_Framework_MockObject_MockObject */ |
| 43 | + private $moduleManagerMock; |
| 44 | + |
| 45 | + /** @var SalableResolverInterface|\PHPUnit_Framework_MockObject_MockObject */ |
| 46 | + private $salableResolverMock; |
| 47 | + |
| 48 | + protected function setUp() |
| 49 | + { |
| 50 | + $eventManager = $this->getMock(\Magento\Framework\Event\Test\Unit\ManagerStub::class, [], [], '', false); |
| 51 | + $scopeConfigMock = $this->getMockForAbstractClass(\Magento\Framework\App\Config\ScopeConfigInterface::class); |
| 52 | + $this->contextMock = $this->getMockBuilder(\Magento\Framework\View\Element\Template\Context::class) |
| 53 | + ->disableOriginalConstructor() |
| 54 | + ->getMock(); |
| 55 | + $this->contextMock->expects($this->any()) |
| 56 | + ->method('getEventManager') |
| 57 | + ->will($this->returnValue($eventManager)); |
| 58 | + $this->contextMock->expects($this->any()) |
| 59 | + ->method('getScopeConfig') |
| 60 | + ->will($this->returnValue($scopeConfigMock)); |
| 61 | + |
| 62 | + $this->saleableItemMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) |
| 63 | + ->setMethods(['getCanShowPrice', 'getPriceInfo']) |
| 64 | + ->disableOriginalConstructor() |
| 65 | + ->getMock(); |
| 66 | + $this->priceMock = $this->getMockBuilder(\Magento\Framework\Pricing\Price\PriceInterface::class) |
| 67 | + ->disableOriginalConstructor() |
| 68 | + ->getMock(); |
| 69 | + $this->rendererPoolMock = $this->getMockBuilder(\Magento\Framework\Pricing\Render\RendererPool::class) |
| 70 | + ->disableOriginalConstructor() |
| 71 | + ->getMock(); |
| 72 | + $this->configurableOptionsProviderMock = $this->getMockBuilder(ConfigurableOptionsProviderInterface::class) |
| 73 | + ->disableOriginalConstructor() |
| 74 | + ->getMock(); |
| 75 | + $this->lowestPriceOptionsProviderMock = $this->getMockBuilder(LowestPriceOptionsProviderInterface::class) |
| 76 | + ->disableOriginalConstructor() |
| 77 | + ->getMock(); |
| 78 | + $this->salableResolverMock = $this->getMockBuilder(SalableResolverInterface::class) |
| 79 | + ->disableOriginalConstructor() |
| 80 | + ->getMock(); |
| 81 | + $this->moduleManagerMock = $this->getMockBuilder(\Magento\Framework\Module\Manager::class) |
| 82 | + ->setMethods(['isEnabled', 'isOutputEnabled']) |
| 83 | + ->disableOriginalConstructor() |
| 84 | + ->getMock(); |
| 85 | + |
| 86 | + /** @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManagerMock */ |
| 87 | + $objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class) |
| 88 | + ->setMethods(['get']) |
| 89 | + ->disableOriginalConstructor() |
| 90 | + ->getMockForAbstractClass(); |
| 91 | + $objectManagerMock->expects(self::at(0))->method('get')->with(SalableResolverInterface::class) |
| 92 | + ->willReturn($this->salableResolverMock); |
| 93 | + $objectManagerMock->expects(self::at(1))->method('get')->with(\Magento\Framework\Module\Manager::class) |
| 94 | + ->willReturn($this->moduleManagerMock); |
| 95 | + \Magento\Framework\App\ObjectManager::setInstance($objectManagerMock); |
| 96 | + |
| 97 | + $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); |
| 98 | + |
| 99 | + $this->priceBox = $this->objectManager->getObject( |
| 100 | + \Magento\ConfigurableProduct\Pricing\Render\TierPriceBox::class, |
| 101 | + [ |
| 102 | + 'context' => $this->contextMock, |
| 103 | + 'saleableItem' => $this->saleableItemMock, |
| 104 | + 'price' => $this->priceMock, |
| 105 | + 'rendererPool' => $this->rendererPoolMock, |
| 106 | + 'configurableOptionsProvider' => $this->configurableOptionsProviderMock, |
| 107 | + 'data' => [], |
| 108 | + 'lowestPriceOptionsProvider' => $this->lowestPriceOptionsProviderMock, |
| 109 | + ] |
| 110 | + ); |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Covers toHtml() with Msrp module disabled. |
| 115 | + * |
| 116 | + * @return void |
| 117 | + */ |
| 118 | + public function testToHtmlMsrpDisabled() |
| 119 | + { |
| 120 | + $this->saleableItemMock->expects($this->any()) |
| 121 | + ->method('getCanShowPrice') |
| 122 | + ->willReturn(true); |
| 123 | + $this->priceMock->expects($this->any()) |
| 124 | + ->method('getPriceCode') |
| 125 | + ->will($this->returnValue(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE)); |
| 126 | + $this->moduleManagerMock->expects($this->any()) |
| 127 | + ->method('isEnabled') |
| 128 | + ->with('Magento_Msrp') |
| 129 | + ->willReturn(false); |
| 130 | + |
| 131 | + $result = $this->priceBox->toHtml(); |
| 132 | + |
| 133 | + $this->assertStringStartsWith('<div', $result); |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * Covers toHtml() with Msrp module enabled. |
| 138 | + * |
| 139 | + * @return void |
| 140 | + */ |
| 141 | + public function testToHtmlMsrpEnabled() |
| 142 | + { |
| 143 | + $this->moduleManagerMock->expects($this->any()) |
| 144 | + ->method('isEnabled') |
| 145 | + ->with('Magento_Msrp') |
| 146 | + ->willReturn(true); |
| 147 | + $this->moduleManagerMock->expects($this->any()) |
| 148 | + ->method('isOutputEnabled') |
| 149 | + ->with('Magento_Msrp') |
| 150 | + ->willReturn(true); |
| 151 | + $priceInterfaceMock = $this->getMockBuilder(Magento\Framework\Pricing\Price\PriceInterface::class) |
| 152 | + ->setMethods(['canApplyMsrp', 'isMinimalPriceLessMsrp']) |
| 153 | + ->disableOriginalConstructor() |
| 154 | + ->getMock(); |
| 155 | + $priceInterfaceMock->expects($this->once()) |
| 156 | + ->method('canApplyMsrp') |
| 157 | + ->with($this->saleableItemMock) |
| 158 | + ->willReturn(true); |
| 159 | + $priceInterfaceMock->expects($this->once()) |
| 160 | + ->method('isMinimalPriceLessMsrp') |
| 161 | + ->with($this->saleableItemMock) |
| 162 | + ->willReturn(true); |
| 163 | + $priceInfoMock = $this->getMockBuilder(\Magento\Framework\Pricing\PriceInfoInterface::class) |
| 164 | + ->disableOriginalConstructor() |
| 165 | + ->getMock(); |
| 166 | + $priceInfoMock->expects($this->once()) |
| 167 | + ->method('getPrice') |
| 168 | + ->with('msrp_price') |
| 169 | + ->willReturn($priceInterfaceMock); |
| 170 | + $this->saleableItemMock->expects($this->any()) |
| 171 | + ->method('getPriceInfo') |
| 172 | + ->willReturn($priceInfoMock); |
| 173 | + |
| 174 | + $this->assertEmpty($this->priceBox->toHtml()); |
| 175 | + } |
| 176 | + |
| 177 | + /** |
| 178 | + * @inheritdoc |
| 179 | + */ |
| 180 | + protected function tearDown() |
| 181 | + { |
| 182 | + // reset ObjectManager instance. |
| 183 | + $reflection = new \ReflectionClass(\Magento\Framework\App\ObjectManager::class); |
| 184 | + $reflectionProperty = $reflection->getProperty('_instance'); |
| 185 | + $reflectionProperty->setAccessible(true); |
| 186 | + $reflectionProperty->setValue(null, null); |
| 187 | + } |
| 188 | +} |
0 commit comments