Skip to content

Commit 23c55c0

Browse files
committed
MAGETWO-62229: There is no Price on product page when product is out of stock
1 parent e837aa4 commit 23c55c0

File tree

1 file changed

+84
-2
lines changed

1 file changed

+84
-2
lines changed

app/code/Magento/ConfigurableProduct/Test/Unit/Pricing/Render/FinalPriceBoxTest.php

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
namespace Magento\ConfigurableProduct\Test\Unit\Pricing\Render;
88

99
use Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolverInterface;
10+
use Magento\Framework\Module\Manager;
11+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1012

1113
/**
1214
* Class FinalPriceBoxTest
@@ -63,6 +65,12 @@ class FinalPriceBoxTest extends \PHPUnit_Framework_TestCase
6365
*/
6466
private $salableResolverMock;
6567

68+
/** @var ObjectManager */
69+
private $objectManager;
70+
71+
/** @var Manager|\PHPUnit_Framework_MockObject_MockObject */
72+
private $moduleManager;
73+
6674
protected function setUp()
6775
{
6876
$this->product = $this->getMock(
@@ -147,12 +155,13 @@ protected function setUp()
147155
->method('getPriceCode')
148156
->will($this->returnValue(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE));
149157

150-
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
158+
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
159+
151160
$this->salableResolverMock = $this->getMockBuilder(SalableResolverInterface::class)
152161
->disableOriginalConstructor()
153162
->getMockForAbstractClass();
154163

155-
$this->object = $objectManager->getObject(
164+
$this->object = $this->objectManager->getObject(
156165
'Magento\Catalog\Pricing\Render\FinalPriceBox',
157166
[
158167
'context' => $context,
@@ -163,11 +172,33 @@ protected function setUp()
163172
'salableResolver' => $this->salableResolverMock
164173
]
165174
);
175+
176+
$this->moduleManager = $this->getMockBuilder(Manager::class)
177+
->setMethods(['isEnabled', 'isOutputEnabled'])
178+
->disableOriginalConstructor()
179+
->getMock();
180+
181+
$this->objectManager->setBackwardCompatibleProperty(
182+
$this->object,
183+
'moduleManager',
184+
$this->moduleManager
185+
);
166186
}
167187

168188
public function testRenderMsrpDisabled()
169189
{
170190
$priceType = $this->getMock('Magento\Msrp\Pricing\Price\MsrpPrice', [], [], '', false);
191+
192+
$this->moduleManager->expects(self::once())
193+
->method('isEnabled')
194+
->with('Magento_Msrp')
195+
->willReturn(true);
196+
197+
$this->moduleManager->expects(self::once())
198+
->method('isOutputEnabled')
199+
->with('Magento_Msrp')
200+
->willReturn(true);
201+
171202
$this->priceInfo->expects($this->once())
172203
->method('getPrice')
173204
->with($this->equalTo('msrp_price'))
@@ -189,6 +220,17 @@ public function testRenderMsrpDisabled()
189220
public function testRenderMsrpEnabled()
190221
{
191222
$priceType = $this->getMock('Magento\Msrp\Pricing\Price\MsrpPrice', [], [], '', false);
223+
224+
$this->moduleManager->expects(self::once())
225+
->method('isEnabled')
226+
->with('Magento_Msrp')
227+
->willReturn(true);
228+
229+
$this->moduleManager->expects(self::once())
230+
->method('isOutputEnabled')
231+
->with('Magento_Msrp')
232+
->willReturn(true);
233+
192234
$this->priceInfo->expects($this->once())
193235
->method('getPrice')
194236
->with($this->equalTo('msrp_price'))
@@ -231,6 +273,16 @@ public function testRenderMsrpEnabled()
231273

232274
public function testRenderMsrpNotRegisteredException()
233275
{
276+
$this->moduleManager->expects(self::once())
277+
->method('isEnabled')
278+
->with('Magento_Msrp')
279+
->willReturn(true);
280+
281+
$this->moduleManager->expects(self::once())
282+
->method('isOutputEnabled')
283+
->with('Magento_Msrp')
284+
->willReturn(true);
285+
234286
$this->logger->expects($this->once())
235287
->method('critical');
236288

@@ -388,4 +440,34 @@ public function testGetCacheKeyInfo()
388440
{
389441
$this->assertArrayHasKey('display_minimal_price', $this->object->getCacheKeyInfo());
390442
}
443+
444+
public function testRenderMsrpModuleDisabled()
445+
{
446+
$this->moduleManager->expects(self::exactly(2))
447+
->method('isEnabled')
448+
->with('Magento_Msrp')
449+
->will($this->onConsecutiveCalls(false, true));
450+
451+
$this->priceInfo->expects($this->never())
452+
->method('getPrice');
453+
454+
$result = $this->object->toHtml();
455+
456+
//assert price wrapper
457+
$this->assertStringStartsWith('<div', $result);
458+
//assert css_selector
459+
$this->assertRegExp('/[final_price]/', $result);
460+
461+
$this->moduleManager->expects(self::once())
462+
->method('isOutputEnabled')
463+
->with('Magento_Msrp')
464+
->willReturn(false);
465+
466+
$result = $this->object->toHtml();
467+
468+
//assert price wrapper
469+
$this->assertStringStartsWith('<div', $result);
470+
//assert css_selector
471+
$this->assertRegExp('/[final_price]/', $result);
472+
}
391473
}

0 commit comments

Comments
 (0)