You are here

function Braintree_CustomerTest::testCreate_withValidationErrors in Commerce Braintree 7

File

braintree_php/tests/integration/CustomerTest.php, line 283

Class

Braintree_CustomerTest

Code

function testCreate_withValidationErrors() {
  $result = Braintree_Customer::create(array(
    'email' => 'invalid',
    'creditCard' => array(
      'number' => 'invalid',
      'billingAddress' => array(
        'streetAddress' => str_repeat('x', 256),
      ),
    ),
  ));
  Braintree_TestHelper::assertPrintable($result);
  $this
    ->assertEquals(false, $result->success);
  $errors = $result->errors
    ->forKey('customer')
    ->onAttribute('email');
  $this
    ->assertEquals(Braintree_Error_Codes::CUSTOMER_EMAIL_IS_INVALID, $errors[0]->code);
  $errors = $result->errors
    ->forKey('customer')
    ->forKey('creditCard')
    ->onAttribute('number');
  $this
    ->assertEquals(Braintree_Error_Codes::CREDIT_CARD_NUMBER_INVALID_LENGTH, $errors[0]->code);
  $errors = $result->errors
    ->forKey('customer')
    ->forKey('creditCard')
    ->forKey('billingAddress')
    ->onAttribute('streetAddress');
  $this
    ->assertEquals(Braintree_Error_Codes::ADDRESS_STREET_ADDRESS_IS_TOO_LONG, $errors[0]->code);
}