assertRegExp('/[final_price]/', $result);
+ }
+
+ public function testNotSalableItem()
+ {
+ $this->salableResolverMock
+ ->expects($this->once())
+ ->method('isSalable')
+ ->with($this->product)
+ ->willReturn(false);
+ $result = $this->object->toHtml();
+
+ $this->assertEmpty($result);
+ }
+
+ public function testRenderMsrpEnabled()
+ {
+ $priceType = $this->getMock('Magento\Msrp\Pricing\Price\MsrpPrice', [], [], '', false);
+ $this->priceInfo->expects($this->once())
+ ->method('getPrice')
+ ->with($this->equalTo('msrp_price'))
+ ->will($this->returnValue($priceType));
+
+ $priceType->expects($this->any())
+ ->method('canApplyMsrp')
+ ->with($this->equalTo($this->product))
+ ->will($this->returnValue(true));
+
+ $priceType->expects($this->any())
+ ->method('isMinimalPriceLessMsrp')
+ ->with($this->equalTo($this->product))
+ ->will($this->returnValue(true));
+
+ $priceBoxRender = $this->getMockBuilder('Magento\Framework\Pricing\Render\PriceBox')
->disableOriginalConstructor()
->getMock();
+ $priceBoxRender->expects($this->once())
+ ->method('toHtml')
+ ->will($this->returnValue('test'));
+
+ $arguments = [
+ 'real_price_html' => '',
+ 'zone' => 'test_zone',
+ ];
+ $this->rendererPool->expects($this->once())
+ ->method('createPriceRender')
+ ->with('msrp_price', $this->product, $arguments)
+ ->will($this->returnValue($priceBoxRender));
+
+ $this->salableResolverMock->expects($this->once())->method('isSalable')->with($this->product)->willReturn(true);
- $priceInfoMock->expects($this->exactly(2))
+ $result = $this->object->toHtml();
+
+ //assert price wrapper
+ $this->assertEquals(
+ '
test
',
+ $result
+ );
+ }
+
+ public function testRenderMsrpNotRegisteredException()
+ {
+ $this->logger->expects($this->once())
+ ->method('critical');
+
+ $this->priceInfo->expects($this->once())
->method('getPrice')
- ->willReturnMap([
- [RegularPrice::PRICE_CODE, $priceMockOne],
- [FinalPrice::PRICE_CODE, $priceMockTwo],
- ]);
+ ->with($this->equalTo('msrp_price'))
+ ->will($this->throwException(new \InvalidArgumentException()));
- $productMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class)
- ->setMethods(['getPriceInfo'])
- ->getMockForAbstractClass();
+ $this->salableResolverMock->expects($this->once())->method('isSalable')->with($this->product)->willReturn(true);
- $productMock->expects($this->exactly(2))
- ->method('getPriceInfo')
- ->willReturn($priceInfoMock);
+ $result = $this->object->toHtml();
+
+ //assert price wrapper
+ $this->assertStringStartsWith('
assertRegExp('/[final_price]/', $result);
+ }
+
+ public function testRenderAmountMinimal()
+ {
+ $priceType = $this->getMock('Magento\Catalog\Pricing\Price\FinalPrice', [], [], '', false);
+ $amount = $this->getMockForAbstractClass('Magento\Framework\Pricing\Amount\AmountInterface');
+ $priceId = 'price_id';
+ $html = 'html';
+ $this->object->setData('price_id', $priceId);
+
+ $arguments = [
+ 'zone' => 'test_zone',
+ 'list_category_page' => true,
+ 'display_label' => 'As low as',
+ 'price_id' => $priceId,
+ 'include_container' => false,
+ 'skip_adjustments' => true,
+ ];
- $this->lowestPriceOptionsProvider->expects($this->once())
- ->method('getProducts')
- ->with($this->saleableItem)
- ->willReturn([$productMock]);
+ $amountRender = $this->getMock('Magento\Framework\Pricing\Render\Amount', ['toHtml'], [], '', false);
+ $amountRender->expects($this->once())
+ ->method('toHtml')
+ ->will($this->returnValue($html));
- $this->assertEquals($expected, $this->model->hasSpecialPrice());
+ $this->priceInfo->expects($this->once())
+ ->method('getPrice')
+ ->with(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE)
+ ->will($this->returnValue($priceType));
+
+ $priceType->expects($this->once())
+ ->method('getMinimalPrice')
+ ->will($this->returnValue($amount));
+
+ $this->rendererPool->expects($this->once())
+ ->method('createAmountRender')
+ ->with($amount, $this->product, $this->price, $arguments)
+ ->will($this->returnValue($amountRender));
+
+ $this->assertEquals($html, $this->object->renderAmountMinimal());
}
/**
- * @return array
+ * @dataProvider hasSpecialPriceProvider
+ * @param float $regularPrice
+ * @param float $finalPrice
+ * @param bool $expectedResult
*/
- public function hasSpecialPriceDataProvider()
+ public function testHasSpecialPrice($regularPrice, $finalPrice, $expectedResult)
+ {
+ $regularPriceType = $this->getMock('Magento\Catalog\Pricing\Price\RegularPrice', [], [], '', false);
+ $finalPriceType = $this->getMock('Magento\Catalog\Pricing\Price\FinalPrice', [], [], '', false);
+ $regularPriceAmount = $this->getMockForAbstractClass('Magento\Framework\Pricing\Amount\AmountInterface');
+ $finalPriceAmount = $this->getMockForAbstractClass('Magento\Framework\Pricing\Amount\AmountInterface');
+
+ $regularPriceAmount->expects($this->once())
+ ->method('getValue')
+ ->will($this->returnValue($regularPrice));
+ $finalPriceAmount->expects($this->once())
+ ->method('getValue')
+ ->will($this->returnValue($finalPrice));
+
+ $regularPriceType->expects($this->once())
+ ->method('getAmount')
+ ->will($this->returnValue($regularPriceAmount));
+ $finalPriceType->expects($this->once())
+ ->method('getAmount')
+ ->will($this->returnValue($finalPriceAmount));
+
+ $this->priceInfo->expects($this->at(0))
+ ->method('getPrice')
+ ->with(\Magento\Catalog\Pricing\Price\RegularPrice::PRICE_CODE)
+ ->will($this->returnValue($regularPriceType));
+ $this->priceInfo->expects($this->at(1))
+ ->method('getPrice')
+ ->with(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE)
+ ->will($this->returnValue($finalPriceType));
+
+ $this->assertEquals($expectedResult, $this->object->hasSpecialPrice());
+ }
+
+ public function hasSpecialPriceProvider()
{
return [
- [10., 20., false],
- [10., 10., false],
- [20., 10., true],
+ [10.0, 20.0, false],
+ [20.0, 10.0, true],
+ [10.0, 10.0, false]
];
}
+
+ public function testShowMinimalPrice()
+ {
+ $finalPrice = 10.0;
+ $minimalPrice = 5.0;
+ $displayMininmalPrice = 2.0;
+
+ $this->object->setDisplayMinimalPrice($displayMininmalPrice);
+
+ $finalPriceType = $this->getMock('Magento\Catalog\Pricing\Price\FinalPrice', [], [], '', false);
+
+ $finalPriceAmount = $this->getMockForAbstractClass('Magento\Framework\Pricing\Amount\AmountInterface');
+ $minimalPriceAmount = $this->getMockForAbstractClass('Magento\Framework\Pricing\Amount\AmountInterface');
+
+ $finalPriceAmount->expects($this->once())
+ ->method('getValue')
+ ->will($this->returnValue($finalPrice));
+ $minimalPriceAmount->expects($this->once())
+ ->method('getValue')
+ ->will($this->returnValue($minimalPrice));
+
+ $finalPriceType->expects($this->at(0))
+ ->method('getAmount')
+ ->will($this->returnValue($finalPriceAmount));
+ $finalPriceType->expects($this->at(1))
+ ->method('getMinimalPrice')
+ ->will($this->returnValue($minimalPriceAmount));
+
+ $this->priceInfo->expects($this->once())
+ ->method('getPrice')
+ ->with(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE)
+ ->will($this->returnValue($finalPriceType));
+
+ $this->assertTrue($this->object->showMinimalPrice());
+ }
+
+ public function testHidePrice()
+ {
+ $this->product->expects($this->any())
+ ->method('getCanShowPrice')
+ ->will($this->returnValue(false));
+
+ $this->assertEmpty($this->object->toHtml());
+ }
+
+ public function testGetCacheKey()
+ {
+ $result = $this->object->getCacheKey();
+ $this->assertStringEndsWith('list-category-page', $result);
+ }
+
+ public function testGetCacheKeyInfo()
+ {
+ $this->assertArrayHasKey('display_minimal_price', $this->object->getCacheKeyInfo());
+ }
}
diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Pricing/Price/FinalPriceTest.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Pricing/Price/FinalPriceTest.php
new file mode 100644
index 0000000000000..25e2340d7b23a
--- /dev/null
+++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Pricing/Price/FinalPriceTest.php
@@ -0,0 +1,71 @@
+productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
+ }
+
+ /**
+ * @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
+ */
+ public function testNullPriceForConfigurbaleIfAllChildIsOutOfStock()
+ {
+ //prepare configurable product
+ $configurableProduct = $this->productRepository->get('configurable', false, null, true);
+ foreach ($configurableProduct->getExtensionAttributes()->getConfigurableProductLinks() as $productId) {
+ $product = $this->productRepository->getById($productId);
+ $product->getExtensionAttributes()->getStockItem()->setIsInStock(0);
+ $this->productRepository->save($product);
+ }
+
+ $finalPrice = Bootstrap::getObjectManager()->create(
+ FinalPrice::class,
+ [
+ 'saleableItem' => $configurableProduct,
+ 'quantity' => 1
+ ]
+ );
+
+ static::assertNull($finalPrice->getValue());
+ }
+
+ /**
+ * @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
+ */
+ public function testNullPriceForConfigurbaleIfAllChildIsDisabled()
+ {
+ //prepare configurable product
+ $configurableProduct = $this->productRepository->get('configurable', false, null, true);
+ foreach ($configurableProduct->getExtensionAttributes()->getConfigurableProductLinks() as $productId) {
+ $product = $this->productRepository->getById($productId);
+ $product->setStatus(Status::STATUS_DISABLED);
+ $this->productRepository->save($product);
+ }
+
+ $finalPrice = Bootstrap::getObjectManager()->create(
+ FinalPrice::class,
+ [
+ 'saleableItem' => $configurableProduct,
+ 'quantity' => 1
+ ]
+ );
+
+ static::assertNull($finalPrice->getValue());
+ }
+}