DataTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Msrp\Test\Unit\Helper;
  7. use Magento\Msrp\Pricing\MsrpPriceCalculatorInterface;
  8. /**
  9. * Class DataTest
  10. */
  11. class DataTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var \Magento\Msrp\Helper\Data
  15. */
  16. protected $helper;
  17. /**
  18. * @var \Magento\Framework\Pricing\PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $priceCurrencyMock;
  21. /**
  22. * @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $productMock;
  25. /**
  26. * @var MsrpPriceCalculatorInterface|\PHPUnit_Framework_MockObject_MockObject
  27. */
  28. private $msrpPriceCalculator;
  29. /**
  30. * @inheritdoc
  31. */
  32. protected function setUp()
  33. {
  34. $this->priceCurrencyMock = $this->createMock(\Magento\Framework\Pricing\PriceCurrencyInterface::class);
  35. $this->productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
  36. ->disableOriginalConstructor()
  37. ->setMethods(['getMsrp', 'getPriceInfo', '__wakeup'])
  38. ->getMock();
  39. $this->msrpPriceCalculator = $this->getMockBuilder(MsrpPriceCalculatorInterface::class)
  40. ->getMockForAbstractClass();
  41. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  42. $this->helper = $objectManager->getObject(
  43. \Magento\Msrp\Helper\Data::class,
  44. [
  45. 'priceCurrency' => $this->priceCurrencyMock,
  46. 'msrpPriceCalculator' => $this->msrpPriceCalculator,
  47. ]
  48. );
  49. }
  50. /**
  51. * @throws \Magento\Framework\Exception\NoSuchEntityException
  52. */
  53. public function testIsMinimalPriceLessMsrp()
  54. {
  55. $msrp = 120;
  56. $convertedFinalPrice = 200;
  57. $this->priceCurrencyMock->expects($this->any())
  58. ->method('convertAndRound')
  59. ->will(
  60. $this->returnCallback(
  61. function ($arg) {
  62. return round(2 * $arg, 2);
  63. }
  64. )
  65. );
  66. $finalPriceMock = $this->getMockBuilder(\Magento\Catalog\Pricing\Price\FinalPrice::class)
  67. ->disableOriginalConstructor()
  68. ->getMock();
  69. $finalPriceMock->expects($this->any())
  70. ->method('getValue')
  71. ->will($this->returnValue($convertedFinalPrice));
  72. $priceInfoMock = $this->getMockBuilder(\Magento\Framework\Pricing\PriceInfo\Base::class)
  73. ->disableOriginalConstructor()
  74. ->getMock();
  75. $priceInfoMock->expects($this->once())
  76. ->method('getPrice')
  77. ->with(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE)
  78. ->will($this->returnValue($finalPriceMock));
  79. $this->msrpPriceCalculator
  80. ->expects($this->any())
  81. ->method('getMsrpPriceValue')
  82. ->willReturn($msrp);
  83. $this->productMock->expects($this->any())
  84. ->method('getPriceInfo')
  85. ->willReturn($priceInfoMock);
  86. $result = $this->helper->isMinimalPriceLessMsrp($this->productMock);
  87. $this->assertTrue($result, "isMinimalPriceLessMsrp returned incorrect value");
  88. }
  89. }