MsrpPriceTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Msrp\Test\Unit\Pricing\Price;
  7. use Magento\Framework\Pricing\PriceInfoInterface;
  8. /**
  9. * Class MsrpPriceTest
  10. */
  11. class MsrpPriceTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var \Magento\Msrp\Pricing\Price\MsrpPrice
  15. */
  16. protected $object;
  17. /**
  18. * @var \PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $helper;
  21. /**
  22. * @var \PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $saleableItem;
  25. /**
  26. * @var \Magento\Catalog\Pricing\Price\BasePrice|\PHPUnit_Framework_MockObject_MockObject
  27. */
  28. protected $price;
  29. /**
  30. * @var \Magento\Framework\Pricing\PriceInfo\Base|\PHPUnit_Framework_MockObject_MockObject
  31. */
  32. protected $priceInfo;
  33. /**
  34. * @var \Magento\Framework\Pricing\Adjustment\Calculator|\PHPUnit_Framework_MockObject_MockObject
  35. */
  36. protected $calculator;
  37. /**
  38. * @var \Magento\Msrp\Model\Config|\PHPUnit_Framework_MockObject_MockObject
  39. */
  40. protected $config;
  41. /**
  42. * @var \Magento\Framework\Pricing\PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
  43. */
  44. protected $priceCurrencyMock;
  45. protected function setUp()
  46. {
  47. $this->saleableItem = $this->createPartialMock(
  48. \Magento\Catalog\Model\Product::class,
  49. ['getPriceInfo', '__wakeup']
  50. );
  51. $this->priceInfo = $this->createMock(\Magento\Framework\Pricing\PriceInfo\Base::class);
  52. $this->price = $this->createMock(\Magento\Catalog\Pricing\Price\BasePrice::class);
  53. $this->priceInfo->expects($this->any())
  54. ->method('getAdjustments')
  55. ->will($this->returnValue([]));
  56. $this->saleableItem->expects($this->any())
  57. ->method('getPriceInfo')
  58. ->will($this->returnValue($this->priceInfo));
  59. $this->priceInfo->expects($this->any())
  60. ->method('getPrice')
  61. ->with($this->equalTo('base_price'))
  62. ->will($this->returnValue($this->price));
  63. $this->calculator = $this->getMockBuilder(\Magento\Framework\Pricing\Adjustment\Calculator::class)
  64. ->disableOriginalConstructor()
  65. ->getMock();
  66. $this->helper = $this->createPartialMock(
  67. \Magento\Msrp\Helper\Data::class,
  68. ['isShowPriceOnGesture', 'getMsrpPriceMessage', 'canApplyMsrp']
  69. );
  70. $this->config = $this->createPartialMock(\Magento\Msrp\Model\Config::class, ['isEnabled']);
  71. $this->priceCurrencyMock = $this->createMock(\Magento\Framework\Pricing\PriceCurrencyInterface::class);
  72. $this->object = new \Magento\Msrp\Pricing\Price\MsrpPrice(
  73. $this->saleableItem,
  74. PriceInfoInterface::PRODUCT_QUANTITY_DEFAULT,
  75. $this->calculator,
  76. $this->priceCurrencyMock,
  77. $this->helper,
  78. $this->config
  79. );
  80. }
  81. public function testIsShowPriceOnGestureTrue()
  82. {
  83. $this->helper->expects($this->once())
  84. ->method('isShowPriceOnGesture')
  85. ->with($this->equalTo($this->saleableItem))
  86. ->will($this->returnValue(true));
  87. $this->assertTrue($this->object->isShowPriceOnGesture());
  88. }
  89. public function testIsShowPriceOnGestureFalse()
  90. {
  91. $this->helper->expects($this->once())
  92. ->method('isShowPriceOnGesture')
  93. ->with($this->equalTo($this->saleableItem))
  94. ->will($this->returnValue(false));
  95. $this->assertFalse($this->object->isShowPriceOnGesture());
  96. }
  97. public function testGetMsrpPriceMessage()
  98. {
  99. $expectedMessage = 'test';
  100. $this->helper->expects($this->once())
  101. ->method('getMsrpPriceMessage')
  102. ->with($this->equalTo($this->saleableItem))
  103. ->will($this->returnValue($expectedMessage));
  104. $this->assertEquals($expectedMessage, $this->object->getMsrpPriceMessage());
  105. }
  106. public function testIsMsrpEnabled()
  107. {
  108. $this->config->expects($this->once())
  109. ->method('isEnabled')
  110. ->will($this->returnValue(true));
  111. $this->assertTrue($this->object->isMsrpEnabled());
  112. }
  113. public function testCanApplyMsrp()
  114. {
  115. $this->helper->expects($this->once())
  116. ->method('canApplyMsrp')
  117. ->with($this->equalTo($this->saleableItem))
  118. ->will($this->returnValue(true));
  119. $this->assertTrue($this->object->canApplyMsrp($this->saleableItem));
  120. }
  121. }