FinalPriceBoxTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Bundle\Test\Unit\Pricing\Render;
  7. use Magento\Bundle\Pricing\Render\FinalPriceBox;
  8. use Magento\Catalog\Pricing\Price\CustomOptionPrice;
  9. class FinalPriceBoxTest extends \PHPUnit\Framework\TestCase
  10. {
  11. /**
  12. * @var FinalPriceBox
  13. */
  14. protected $model;
  15. /**
  16. * @var \Magento\Framework\Pricing\SaleableInterface|\PHPUnit_Framework_MockObject_MockObject
  17. */
  18. protected $saleableItem;
  19. protected function setUp()
  20. {
  21. $this->saleableItem = $this->createMock(\Magento\Framework\Pricing\SaleableInterface::class);
  22. $objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  23. $this->model = $objectHelper->getObject(
  24. \Magento\Bundle\Pricing\Render\FinalPriceBox::class,
  25. ['saleableItem' => $this->saleableItem]
  26. );
  27. }
  28. /**
  29. * @dataProvider showRangePriceDataProvider
  30. */
  31. public function testShowRangePrice($optMinValue, $optMaxValue, $custMinValue, $custMaxValue, $expectedShowRange)
  32. {
  33. $enableCustomOptionMocks = ($optMinValue == $optMaxValue);
  34. $priceInfo = $this->createMock(\Magento\Framework\Pricing\PriceInfo\Base::class);
  35. $bundlePrice = $this->getMockBuilder(\Magento\Bundle\Pricing\Price\FinalPrice::class)
  36. ->disableOriginalConstructor()
  37. ->getMock();
  38. $customOptionPrice = $this->getMockBuilder(\Magento\Catalog\Pricing\Price\CustomOptionPrice::class)
  39. ->disableOriginalConstructor()
  40. ->getMock();
  41. $this->saleableItem->expects($this->atLeastOnce())
  42. ->method('getPriceInfo')
  43. ->will($this->returnValue($priceInfo));
  44. $priceInfo->expects($this->at(0))
  45. ->method('getPrice')
  46. ->with(\Magento\Bundle\Pricing\Price\FinalPrice::PRICE_CODE)
  47. ->will($this->returnValue($bundlePrice));
  48. if ($enableCustomOptionMocks) {
  49. $priceInfo->expects($this->at(1))
  50. ->method('getPrice')
  51. ->with(CustomOptionPrice::PRICE_CODE)
  52. ->will($this->returnValue($customOptionPrice));
  53. }
  54. $bundlePrice->expects($this->once())
  55. ->method('getMinimalPrice')
  56. ->will($this->returnValue($optMinValue));
  57. $bundlePrice->expects($this->once())
  58. ->method('getMaximalPrice')
  59. ->will($this->returnValue($optMaxValue));
  60. if ($enableCustomOptionMocks) {
  61. $customOptionPrice->expects($this->at(0))
  62. ->method('getCustomOptionRange')
  63. ->will($this->returnValue($custMinValue));
  64. $customOptionPrice->expects($this->at(1))
  65. ->method('getCustomOptionRange')
  66. ->will($this->returnValue($custMaxValue));
  67. }
  68. $this->assertEquals($expectedShowRange, $this->model->showRangePrice());
  69. }
  70. /**
  71. * @return array
  72. */
  73. public function showRangePriceDataProvider()
  74. {
  75. return [
  76. 'bundle options different, custom options noop' => [
  77. 'optMinValue' => 40.2,
  78. 'optMaxValue' => 45.,
  79. 'custMinValue' => 0,
  80. 'custMaxValue' => 0,
  81. 'expectedShowRange' => true
  82. ],
  83. 'bundle options same boolean, custom options same boolean' => [
  84. 'optMinValue' => false,
  85. 'optMaxValue' => false,
  86. 'custMinValue' => false,
  87. 'custMaxValue' => false,
  88. 'expectedShowRange' => false
  89. ],
  90. 'bundle options same numeric, custom options same' => [
  91. 'optMinValue' => 45.0,
  92. 'optMaxValue' => 45,
  93. 'custMinValue' => 1.0,
  94. 'custMaxValue' => 1,
  95. 'expectedShowRange' => false
  96. ],
  97. 'bundle options same numeric, custom options different' => [
  98. 'optMinValue' => 45.0,
  99. 'optMaxValue' => 45.,
  100. 'custMinValue' => 0,
  101. 'custMaxValue' => 1,
  102. 'expectedShowRange' => true
  103. ],
  104. ];
  105. }
  106. }