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