FreeTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Test\Unit\Model\Method;
  7. /**
  8. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  9. */
  10. class FreeTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /** @var \Magento\Payment\Model\Method\Free */
  13. protected $methodFree;
  14. /** @var \PHPUnit_Framework_MockObject_MockObject */
  15. protected $scopeConfig;
  16. /** @var \PHPUnit_Framework_MockObject_MockObject */
  17. protected $currencyPrice;
  18. protected function setUp()
  19. {
  20. $paymentData = $this->createMock(\Magento\Payment\Helper\Data::class);
  21. $this->scopeConfig = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
  22. $this->currencyPrice = $this->getMockBuilder(\Magento\Framework\Pricing\PriceCurrencyInterface::class)
  23. ->getMock();
  24. $context = $this->createPartialMock(\Magento\Framework\Model\Context::class, ['getEventDispatcher']);
  25. $eventManagerMock = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
  26. $context->expects($this->any())->method('getEventDispatcher')->willReturn($eventManagerMock);
  27. $registry = $this->createMock(\Magento\Framework\Registry::class);
  28. $extensionAttributesFactory = $this->createMock(\Magento\Framework\Api\ExtensionAttributesFactory::class);
  29. $customAttributeFactory = $this->createMock(\Magento\Framework\Api\AttributeValueFactory::class);
  30. $loggerMock = $this->getMockBuilder(\Magento\Payment\Model\Method\Logger::class)
  31. ->setConstructorArgs([$this->getMockForAbstractClass(\Psr\Log\LoggerInterface::class)])
  32. ->getMock();
  33. $this->methodFree = new \Magento\Payment\Model\Method\Free(
  34. $context,
  35. $registry,
  36. $extensionAttributesFactory,
  37. $customAttributeFactory,
  38. $paymentData,
  39. $this->scopeConfig,
  40. $loggerMock,
  41. $this->currencyPrice
  42. );
  43. }
  44. /**
  45. * @param string $orderStatus
  46. * @param string $paymentAction
  47. * @param mixed $result
  48. * @dataProvider getConfigPaymentActionProvider
  49. */
  50. public function testGetConfigPaymentAction($orderStatus, $paymentAction, $result)
  51. {
  52. $this->scopeConfig->expects($this->at(0))
  53. ->method('getValue')
  54. ->will($this->returnValue($orderStatus));
  55. if ($orderStatus != 'pending') {
  56. $this->scopeConfig->expects($this->at(1))
  57. ->method('getValue')
  58. ->will($this->returnValue($paymentAction));
  59. }
  60. $this->assertEquals($result, $this->methodFree->getConfigPaymentAction());
  61. }
  62. /**
  63. * @param float $grandTotal
  64. * @param bool $isActive
  65. * @param bool $notEmptyQuote
  66. * @param bool $result
  67. * @dataProvider getIsAvailableProvider
  68. */
  69. public function testIsAvailable($grandTotal, $isActive, $notEmptyQuote, $result)
  70. {
  71. $quote = null;
  72. if ($notEmptyQuote) {
  73. $quote = $this->createMock(\Magento\Quote\Model\Quote::class);
  74. $quote->expects($this->any())
  75. ->method('__call')
  76. ->with($this->equalTo('getGrandTotal'))
  77. ->will($this->returnValue($grandTotal));
  78. }
  79. $this->currencyPrice->expects($this->any())
  80. ->method('round')
  81. ->willReturnArgument(0);
  82. $this->scopeConfig->expects($this->any())
  83. ->method('getValue')
  84. ->will($this->returnValue($isActive));
  85. $this->assertEquals($result, $this->methodFree->isAvailable($quote));
  86. }
  87. /**
  88. * @return array
  89. */
  90. public function getIsAvailableProvider()
  91. {
  92. return [
  93. [0, true, true, true],
  94. [0.1, true, true, false],
  95. [0, false, false, false],
  96. [1, true, false, false],
  97. [0, true, false, false]
  98. ];
  99. }
  100. /**
  101. * @return array
  102. */
  103. public function getConfigPaymentActionProvider()
  104. {
  105. return [
  106. ['pending', 'action', null],
  107. ['processing', 'payment_action', 'payment_action']
  108. ];
  109. }
  110. }