LinkPriceTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Downloadable\Test\Unit\Pricing\Price;
  7. /**
  8. * Class LinkPriceTest
  9. */
  10. class LinkPriceTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\Downloadable\Pricing\Price\LinkPrice
  14. */
  15. protected $linkPrice;
  16. /**
  17. * @var \Magento\Framework\Pricing\Amount\Base|\PHPUnit_Framework_MockObject_MockObject
  18. */
  19. protected $amountMock;
  20. /**
  21. * @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject
  22. */
  23. protected $saleableItemMock;
  24. /**
  25. * @var \Magento\Framework\Pricing\Adjustment\Calculator|\PHPUnit_Framework_MockObject_MockObject
  26. */
  27. protected $calculatorMock;
  28. /**
  29. * @var \Magento\Downloadable\Model\ResourceModel\Link|\PHPUnit_Framework_MockObject_MockObject
  30. */
  31. protected $linkMock;
  32. /**
  33. * @var \Magento\Framework\Pricing\PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
  34. */
  35. protected $priceCurrencyMock;
  36. /**
  37. * Test setUp
  38. */
  39. protected function setUp()
  40. {
  41. $this->saleableItemMock = $this->createMock(\Magento\Catalog\Model\Product::class);
  42. $this->amountMock = $this->createMock(\Magento\Framework\Pricing\Amount\Base::class);
  43. $this->calculatorMock = $this->createMock(\Magento\Framework\Pricing\Adjustment\Calculator::class);
  44. $this->linkMock = $this->createPartialMock(
  45. \Magento\Downloadable\Model\Link::class,
  46. ['getPrice', 'getProduct', '__wakeup']
  47. );
  48. $this->priceCurrencyMock = $this->createMock(\Magento\Framework\Pricing\PriceCurrencyInterface::class);
  49. $this->linkPrice = new \Magento\Downloadable\Pricing\Price\LinkPrice(
  50. $this->saleableItemMock,
  51. 1,
  52. $this->calculatorMock,
  53. $this->priceCurrencyMock
  54. );
  55. }
  56. public function testGetLinkAmount()
  57. {
  58. $amount = 100;
  59. $convertedAmount = 50;
  60. $this->linkMock->expects($this->once())
  61. ->method('getPrice')
  62. ->will($this->returnValue($amount));
  63. $this->linkMock->expects($this->once())
  64. ->method('getProduct')
  65. ->will($this->returnValue($this->saleableItemMock));
  66. $this->priceCurrencyMock->expects($this->once())
  67. ->method('convertAndRound')
  68. ->with($amount)
  69. ->will($this->returnValue($convertedAmount));
  70. $this->calculatorMock->expects($this->once())
  71. ->method('getAmount')
  72. ->with($convertedAmount, $this->equalTo($this->saleableItemMock))
  73. ->will($this->returnValue($convertedAmount));
  74. $result = $this->linkPrice->getLinkAmount($this->linkMock);
  75. $this->assertEquals($convertedAmount, $result);
  76. }
  77. }