Skip to content

Commit 38f8a47

Browse files
ENGCOM-6917: TierPriceBox toHtml method should be return with string #26863
2 parents 4ae0510 + 96b764c commit 38f8a47

File tree

2 files changed

+118
-2
lines changed

2 files changed

+118
-2
lines changed

app/code/Magento/ConfigurableProduct/Pricing/Render/TierPriceBox.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
/**
1111
* Responsible for displaying tier price box on configurable product page.
12-
*
13-
* @package Magento\ConfigurableProduct\Pricing\Render
1412
*/
1513
class TierPriceBox extends FinalPriceBox
1614
{
@@ -23,6 +21,7 @@ public function toHtml()
2321
if (!$this->isMsrpPriceApplicable() && $this->isTierPriceApplicable()) {
2422
return parent::toHtml();
2523
}
24+
return '';
2625
}
2726

2827
/**
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ConfigurableProduct\Test\Unit\Pricing\Render;
9+
10+
use Magento\Catalog\Model\Product;
11+
use Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolverInterface;
12+
use Magento\Catalog\Pricing\Price\MinimalPriceCalculatorInterface;
13+
use Magento\ConfigurableProduct\Pricing\Price\ConfigurableOptionsProviderInterface;
14+
use Magento\ConfigurableProduct\Pricing\Render\TierPriceBox;
15+
use Magento\Framework\Pricing\Price\PriceInterface;
16+
use Magento\Framework\Pricing\PriceInfoInterface;
17+
use Magento\Framework\Pricing\Render\RendererPool;
18+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
19+
use Magento\Framework\View\Element\Template\Context;
20+
use Magento\Msrp\Pricing\Price\MsrpPrice;
21+
use PHPUnit\Framework\MockObject\MockObject;
22+
23+
class TierPriceBoxTest extends \PHPUnit\Framework\TestCase
24+
{
25+
/**
26+
* @var Context|MockObject
27+
*/
28+
private $context;
29+
30+
/**
31+
* @var Product|MockObject
32+
*/
33+
private $saleableItem;
34+
35+
/**
36+
* @var PriceInterface|MockObject
37+
*/
38+
private $price;
39+
40+
/**
41+
* @var RendererPool|MockObject
42+
*/
43+
private $rendererPool;
44+
45+
/**
46+
* @var SalableResolverInterface|MockObject
47+
*/
48+
private $salableResolver;
49+
50+
/**
51+
* @var MinimalPriceCalculatorInterface|MockObject
52+
*/
53+
private $minimalPriceCalculator;
54+
55+
/**
56+
* @var ConfigurableOptionsProviderInterface|MockObject
57+
*/
58+
private $configurableOptionsProvider;
59+
60+
/**
61+
* @var TierPriceBox
62+
*/
63+
private $model;
64+
65+
/**
66+
* @inheritDoc
67+
*/
68+
protected function setUp(): void
69+
{
70+
$this->context = $this->createPartialMock(Context::class, []);
71+
$this->saleableItem = $this->createPartialMock(Product::class, ['getPriceInfo']);
72+
$this->price = $this->createMock(PriceInterface::class);
73+
$this->rendererPool = $this->createPartialMock(RendererPool::class, []);
74+
$this->salableResolver = $this->createPartialMock(SalableResolverInterface::class, ['isSalable']);
75+
$this->minimalPriceCalculator = $this->createMock(MinimalPriceCalculatorInterface::class);
76+
$this->configurableOptionsProvider = $this->createMock(ConfigurableOptionsProviderInterface::class);
77+
78+
$this->model = (new ObjectManager($this))->getObject(
79+
TierPriceBox::class,
80+
[
81+
'context' => $this->context,
82+
'saleableItem' => $this->saleableItem,
83+
'price' => $this->price,
84+
'rendererPool' => $this->rendererPool,
85+
'salableResolver' => $this->salableResolver,
86+
'minimalPriceCalculator' => $this->minimalPriceCalculator,
87+
'configurableOptionsProvider' => $this->configurableOptionsProvider,
88+
]
89+
);
90+
}
91+
92+
public function testToHtmlEmptyWhenMsrpPriceIsApplicable(): void
93+
{
94+
$msrpPriceMock = $this->createPartialMock(
95+
MsrpPrice::class,
96+
['canApplyMsrp', 'isMinimalPriceLessMsrp']
97+
);
98+
$msrpPriceMock->expects($this->once())
99+
->method('canApplyMsrp')
100+
->willReturn(true);
101+
$msrpPriceMock->expects($this->once())
102+
->method('isMinimalPriceLessMsrp')
103+
->willReturn(true);
104+
105+
$priceInfoMock = $this->createMock(PriceInfoInterface::class);
106+
$priceInfoMock->expects($this->once())
107+
->method('getPrice')
108+
->willReturn($msrpPriceMock);
109+
110+
$this->saleableItem->expects($this->once())
111+
->method('getPriceInfo')
112+
->willReturn($priceInfoMock);
113+
114+
$result = $this->model->toHtml();
115+
$this->assertSame('', $result);
116+
}
117+
}

0 commit comments

Comments
 (0)