You are here

function Braintree_CreditCardTest::testCreate_withValidationErrors in Commerce Braintree 7

File

braintree_php/tests/integration/CreditCardTest.php, line 203

Class

Braintree_CreditCardTest

Code

function testCreate_withValidationErrors() {
  $customer = Braintree_Customer::createNoValidate();
  $result = Braintree_CreditCard::create(array(
    'expirationDate' => 'invalid',
    'billingAddress' => array(
      'countryName' => 'Tuvalu',
      'countryCodeAlpha2' => 'US',
    ),
  ));
  $this
    ->assertFalse($result->success);
  $errors = $result->errors
    ->forKey('creditCard')
    ->onAttribute('expirationDate');
  $this
    ->assertEquals(Braintree_Error_Codes::CREDIT_CARD_EXPIRATION_DATE_IS_INVALID, $errors[0]->code);
  $this
    ->assertEquals(1, preg_match('/Credit card number is required\\./', $result->message));
  $this
    ->assertEquals(1, preg_match('/Customer ID is required\\./', $result->message));
  $this
    ->assertEquals(1, preg_match('/Expiration date is invalid\\./', $result->message));
  $errors = $result->errors
    ->forKey('creditCard')
    ->forKey('billingAddress')
    ->onAttribute('base');
  $this
    ->assertEquals(Braintree_Error_Codes::ADDRESS_INCONSISTENT_COUNTRY, $errors[0]->code);
}