AvsEmsCodeMapperTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Test\Unit\Model\Payflow;
  7. use Magento\Paypal\Model\Config;
  8. use Magento\Paypal\Model\Info;
  9. use Magento\Paypal\Model\Payflow\AvsEmsCodeMapper;
  10. use Magento\Sales\Api\Data\OrderPaymentInterface;
  11. use PHPUnit_Framework_MockObject_MockObject as MockObject;
  12. class AvsEmsCodeMapperTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @var AvsEmsCodeMapper
  16. */
  17. private $mapper;
  18. /**
  19. * @inheritdoc
  20. */
  21. protected function setUp()
  22. {
  23. $this->mapper = new AvsEmsCodeMapper();
  24. }
  25. /**
  26. * Checks different variations for AVS codes mapping.
  27. *
  28. * @covers \Magento\Paypal\Model\Payflow\AvsEmsCodeMapper::getCode
  29. * @param string $avsZip
  30. * @param string $avsStreet
  31. * @param string $expected
  32. * @dataProvider getCodeDataProvider
  33. */
  34. public function testGetCode($avsZip, $avsStreet, $expected)
  35. {
  36. /** @var OrderPaymentInterface|MockObject $orderPayment */
  37. $orderPayment = $this->getMockBuilder(OrderPaymentInterface::class)
  38. ->disableOriginalConstructor()
  39. ->getMock();
  40. $orderPayment->expects(self::once())
  41. ->method('getMethod')
  42. ->willReturn(Config::METHOD_PAYFLOWPRO);
  43. $orderPayment->expects(self::once())
  44. ->method('getAdditionalInformation')
  45. ->willReturn([
  46. Info::PAYPAL_AVSZIP => $avsZip,
  47. Info::PAYPAL_AVSADDR => $avsStreet
  48. ]);
  49. self::assertEquals($expected, $this->mapper->getCode($orderPayment));
  50. }
  51. /**
  52. * Checks a test case, when payment order is not Payflow payment method.
  53. *
  54. * @covers \Magento\Paypal\Model\Payflow\AvsEmsCodeMapper::getCode
  55. * @expectedException \InvalidArgumentException
  56. * @expectedExceptionMessage The "some_payment" does not supported by Payflow AVS mapper.
  57. */
  58. public function testGetCodeWithException()
  59. {
  60. /** @var OrderPaymentInterface|MockObject $orderPayment */
  61. $orderPayment = $this->getMockBuilder(OrderPaymentInterface::class)
  62. ->disableOriginalConstructor()
  63. ->getMock();
  64. $orderPayment->expects(self::exactly(2))
  65. ->method('getMethod')
  66. ->willReturn('some_payment');
  67. $this->mapper->getCode($orderPayment);
  68. }
  69. /**
  70. * Gets list of AVS codes.
  71. *
  72. * @return array
  73. */
  74. public function getCodeDataProvider()
  75. {
  76. return [
  77. ['avsZip' => null, 'avsStreet' => null, 'expected' => ''],
  78. ['avsZip' => null, 'avsStreet' => 'Y', 'expected' => ''],
  79. ['avsZip' => 'Y', 'avsStreet' => null, 'expected' => ''],
  80. ['avsZip' => 'Y', 'avsStreet' => 'Y', 'expected' => 'Y'],
  81. ['avsZip' => 'N', 'avsStreet' => 'Y', 'expected' => 'A'],
  82. ['avsZip' => 'Y', 'avsStreet' => 'N', 'expected' => 'Z'],
  83. ['avsZip' => 'N', 'avsStreet' => 'N', 'expected' => 'N'],
  84. ['avsZip' => 'X', 'avsStreet' => 'Y', 'expected' => ''],
  85. ['avsZip' => 'N', 'avsStreet' => 'X', 'expected' => ''],
  86. ['avsZip' => '', 'avsStreet' => 'Y', 'expected' => ''],
  87. ['avsZip' => 'N', 'avsStreet' => '', 'expected' => '']
  88. ];
  89. }
  90. }