|
| 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