|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Omnipay\Braintree\Message; |
| 4 | + |
| 5 | +use Mockery; |
| 6 | +use Omnipay\Tests\TestCase; |
| 7 | + |
| 8 | +class AbstractRequestTest extends TestCase |
| 9 | +{ |
| 10 | + /** |
| 11 | + * @var AbstractRequest |
| 12 | + */ |
| 13 | + private $request; |
| 14 | + |
| 15 | + public function setUp() |
| 16 | + { |
| 17 | + $this->request = Mockery::mock('\Omnipay\Braintree\Message\AbstractRequest')->makePartial(); |
| 18 | + $this->request->initialize(); |
| 19 | + } |
| 20 | + |
| 21 | + /** |
| 22 | + * @dataProvider provideKeepsData |
| 23 | + * @param string $field |
| 24 | + * @param string $value |
| 25 | + */ |
| 26 | + public function testKeepsData($field, $value) |
| 27 | + { |
| 28 | + $field = ucfirst($field); |
| 29 | + $this->assertSame($this->request, $this->request->{"set$field"}($value)); |
| 30 | + $this->assertSame($value, $this->request->{"get$field"}()); |
| 31 | + } |
| 32 | + |
| 33 | + public function provideKeepsData(){ |
| 34 | + return array( |
| 35 | + array('token', 'abc123'), |
| 36 | + array('merchantId', 'abc123'), |
| 37 | + array('publicKey', 'abc123'), |
| 38 | + array('privateKey', 'abc123'), |
| 39 | + array('billingAddressId', 'abc123'), |
| 40 | + array('channel', 'abc123'), |
| 41 | + array('customFields', ['a' => 'b']), |
| 42 | + array('customerId', 'abc123'), |
| 43 | + array('descriptor', array('a' => 'b')), |
| 44 | + array('deviceData', 'abc123'), |
| 45 | + array('deviceSessionId', 'abc123'), |
| 46 | + array('merchantAccountId', 'abc123'), |
| 47 | + array('recurring', true), |
| 48 | + array('addBillingAddressToPaymentMethod', true), |
| 49 | + array('holdInEscrow', true), |
| 50 | + array('storeInVault', true), |
| 51 | + array('storeShippingAddressInVault', true), |
| 52 | + array('shippingAddressId', 'abc123'), |
| 53 | + array('taxAmount', '10.00'), |
| 54 | + array('taxExempt', true), |
| 55 | + ); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @dataProvider provideMakesBool |
| 60 | + * @param string $field |
| 61 | + */ |
| 62 | + public function testMakesBool($field) |
| 63 | + { |
| 64 | + $field = ucfirst($field); |
| 65 | + |
| 66 | + $this->assertSame($this->request, $this->request->{"set$field"}(0)); |
| 67 | + $this->assertSame(false, $this->request->{"get$field"}()); |
| 68 | + |
| 69 | + $this->assertSame($this->request, $this->request->{"set$field"}(1)); |
| 70 | + $this->assertSame(true, $this->request->{"get$field"}()); |
| 71 | + } |
| 72 | + |
| 73 | + public function provideMakesBool(){ |
| 74 | + return array( |
| 75 | + array('recurring'), |
| 76 | + array('addBillingAddressToPaymentMethod'), |
| 77 | + array('holdInEscrow'), |
| 78 | + array('storeInVault'), |
| 79 | + array('storeInVaultOnSuccess'), |
| 80 | + array('storeShippingAddressInVault'), |
| 81 | + ); |
| 82 | + } |
| 83 | + |
| 84 | + public function testCardData() |
| 85 | + { |
| 86 | + $card = array( |
| 87 | + 'firstName' => 'Example', |
| 88 | + 'lastName' => 'User', |
| 89 | + 'company' => 'League', |
| 90 | + 'billingAddress1' => '123 Billing St', |
| 91 | + 'billingAddress2' => 'Billsville', |
| 92 | + 'billingCity' => 'Billstown', |
| 93 | + 'billingPostcode' => '12345', |
| 94 | + 'billingState' => 'CA', |
| 95 | + 'billingCountry' => 'US', |
| 96 | + 'billingPhone' => '(555) 123-4567', |
| 97 | + 'shippingAddress1' => '123 Shipping St', |
| 98 | + 'shippingAddress2' => 'Shipsville', |
| 99 | + 'shippingCity' => 'Shipstown', |
| 100 | + 'shippingPostcode' => '54321', |
| 101 | + 'shippingState' => 'NY', |
| 102 | + 'shippingCountry' => 'US', |
| 103 | + ); |
| 104 | + |
| 105 | + $this->request->setCard($card); |
| 106 | + $data = $this->request->getCardData(); |
| 107 | + |
| 108 | + $this->assertSame($card['firstName'], $data['billing']['firstName']); |
| 109 | + $this->assertSame($card['lastName'], $data['billing']['lastName']); |
| 110 | + $this->assertSame($card['company'], $data['billing']['company']); |
| 111 | + $this->assertSame($card['billingAddress1'], $data['billing']['streetAddress']); |
| 112 | + $this->assertSame($card['billingAddress2'], $data['billing']['extendedAddress']); |
| 113 | + $this->assertSame($card['billingCity'], $data['billing']['locality']); |
| 114 | + $this->assertSame($card['billingPostcode'], $data['billing']['postalCode']); |
| 115 | + $this->assertSame($card['billingState'], $data['billing']['region']); |
| 116 | + $this->assertSame($card['billingCountry'], $data['billing']['countryName']); |
| 117 | + |
| 118 | + $this->assertSame($card['firstName'], $data['shipping']['firstName']); |
| 119 | + $this->assertSame($card['lastName'], $data['shipping']['lastName']); |
| 120 | + $this->assertSame($card['company'], $data['shipping']['company']); |
| 121 | + $this->assertSame($card['shippingAddress1'], $data['shipping']['streetAddress']); |
| 122 | + $this->assertSame($card['shippingAddress2'], $data['shipping']['extendedAddress']); |
| 123 | + $this->assertSame($card['shippingCity'], $data['shipping']['locality']); |
| 124 | + $this->assertSame($card['shippingPostcode'], $data['shipping']['postalCode']); |
| 125 | + $this->assertSame($card['shippingState'], $data['shipping']['region']); |
| 126 | + $this->assertSame($card['shippingCountry'], $data['shipping']['countryName']); |
| 127 | + |
| 128 | + } |
| 129 | +} |
0 commit comments