Skip to content

Commit a653f30

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-62229' into 2.1-prs2
2 parents b808810 + e837aa4 commit a653f30

File tree

2 files changed

+114
-7
lines changed

2 files changed

+114
-7
lines changed

app/code/Magento/Catalog/Pricing/Render/FinalPriceBox.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
namespace Magento\Catalog\Pricing\Render;
88

99
use Magento\Catalog\Pricing\Price;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Module\Manager;
1012
use Magento\Framework\Pricing\Render;
1113
use Magento\Framework\Pricing\Render\PriceBox as BasePriceBox;
1214
use Magento\Msrp\Pricing\Price\MsrpPrice;
@@ -29,6 +31,9 @@ class FinalPriceBox extends BasePriceBox
2931
*/
3032
private $salableResolver;
3133

34+
/** @var Manager */
35+
private $moduleManager;
36+
3237
/**
3338
* @param Context $context
3439
* @param SaleableInterface $saleableItem
@@ -84,8 +89,14 @@ protected function _toHtml()
8489
*
8590
* @return bool
8691
*/
87-
protected function isMsrpPriceApplicable()
92+
private function isMsrpPriceApplicable()
8893
{
94+
$moduleManager = $this->getModuleManager();
95+
96+
if (!$moduleManager->isEnabled('Magento_Msrp') || !$moduleManager->isOutputEnabled('Magento_Msrp') ) {
97+
return false;
98+
}
99+
89100
try {
90101
/** @var MsrpPrice $msrpPriceType */
91102
$msrpPriceType = $this->getSaleableItem()->getPriceInfo()->getPrice('msrp_price');
@@ -99,6 +110,7 @@ protected function isMsrpPriceApplicable()
99110
}
100111

101112
$product = $this->getSaleableItem();
113+
102114
return $msrpPriceType->canApplyMsrp($product) && $msrpPriceType->isMinimalPriceLessMsrp($product);
103115
}
104116

@@ -186,4 +198,16 @@ public function getCacheKeyInfo()
186198
$cacheKeys['display_minimal_price'] = $this->getDisplayMinimalPrice();
187199
return $cacheKeys;
188200
}
201+
202+
/**
203+
* @deprecated
204+
* @return Manager
205+
*/
206+
private function getModuleManager()
207+
{
208+
if ($this->moduleManager === null) {
209+
$this->moduleManager = ObjectManager::getInstance()->get(Manager::class);
210+
}
211+
return $this->moduleManager;
212+
}
189213
}

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

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
namespace Magento\Catalog\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(
@@ -138,21 +146,22 @@ protected function setUp()
138146
->method('getUrlBuilder')
139147
->will($this->returnValue($urlBuilder));
140148

141-
$this->rendererPool = $this->getMockBuilder('Magento\Framework\Pricing\Render\RendererPool')
149+
$this->rendererPool = $this->getMockBuilder(\Magento\Framework\Pricing\Render\RendererPool::class)
142150
->disableOriginalConstructor()
143151
->getMock();
144152

145-
$this->price = $this->getMock('Magento\Framework\Pricing\Price\PriceInterface');
153+
$this->price = $this->getMock(\Magento\Framework\Pricing\Price\PriceInterface::class);
146154
$this->price->expects($this->any())
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
{
170-
$priceType = $this->getMock('Magento\Msrp\Pricing\Price\MsrpPrice', [], [], '', false);
190+
$priceType = $this->getMock(\Magento\Msrp\Pricing\Price\MsrpPrice::class, [], [], '', 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'))
@@ -188,7 +219,19 @@ public function testRenderMsrpDisabled()
188219

189220
public function testRenderMsrpEnabled()
190221
{
191-
$priceType = $this->getMock('Magento\Msrp\Pricing\Price\MsrpPrice', [], [], '', false);
222+
$priceType = $this->getMock(\Magento\Msrp\Pricing\Price\MsrpPrice::class, [], [], '', 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+
234+
192235
$this->priceInfo->expects($this->once())
193236
->method('getPrice')
194237
->with($this->equalTo('msrp_price'))
@@ -231,6 +274,16 @@ public function testRenderMsrpEnabled()
231274

232275
public function testRenderMsrpNotRegisteredException()
233276
{
277+
$this->moduleManager->expects(self::once())
278+
->method('isEnabled')
279+
->with('Magento_Msrp')
280+
->willReturn(true);
281+
282+
$this->moduleManager->expects(self::once())
283+
->method('isOutputEnabled')
284+
->with('Magento_Msrp')
285+
->willReturn(true);
286+
234287
$this->logger->expects($this->once())
235288
->method('critical');
236289

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

0 commit comments

Comments
 (0)