You are here

class Braintree_CreditCardTest in Commerce Braintree 7

Same name in this branch
  1. 7 braintree_php/tests/unit/CreditCardTest.php \Braintree_CreditCardTest
  2. 7 braintree_php/tests/integration/CreditCardTest.php \Braintree_CreditCardTest

Hierarchy

Expanded class hierarchy of Braintree_CreditCardTest

File

braintree_php/tests/unit/CreditCardTest.php, line 4

View source
class Braintree_CreditCardTest extends PHPUnit_Framework_TestCase {
  function testGet_givesErrorIfInvalidProperty() {
    $this
      ->setExpectedException('PHPUnit_Framework_Error', 'Undefined property on Braintree_CreditCard: foo');
    $cc = Braintree_CreditCard::factory(array());
    $cc->foo;
  }
  function testCreate_throwsIfInvalidKey() {
    $this
      ->setExpectedException('InvalidArgumentException', 'invalid keys: invalidKey');
    Braintree_CreditCard::create(array(
      'invalidKey' => 'foo',
    ));
  }
  function testIsDefault() {
    $creditCard = Braintree_CreditCard::factory(array(
      'default' => true,
    ));
    $this
      ->assertTrue($creditCard
      ->isDefault());
    $creditCard = Braintree_CreditCard::factory(array(
      'default' => false,
    ));
    $this
      ->assertFalse($creditCard
      ->isDefault());
  }
  function testMaskedNumber() {
    $creditCard = Braintree_CreditCard::factory(array(
      'bin' => '123456',
      'last4' => '7890',
    ));
    $this
      ->assertEquals('123456******7890', $creditCard->maskedNumber);
  }
  function testCreateSignature() {
    $expected = array(
      'billingAddressId',
      'cardholderName',
      'cvv',
      'number',
      'expirationDate',
      'expirationMonth',
      'expirationYear',
      'token',
      array(
        'options' => array(
          'makeDefault',
          'verificationMerchantAccountId',
          'verifyCard',
          'failOnDuplicatePaymentMethod',
        ),
      ),
      array(
        'billingAddress' => array(
          'firstName',
          'lastName',
          'company',
          'countryCodeAlpha2',
          'countryCodeAlpha3',
          'countryCodeNumeric',
          'countryName',
          'extendedAddress',
          'locality',
          'region',
          'postalCode',
          'streetAddress',
        ),
      ),
      'customerId',
    );
    $this
      ->assertEquals($expected, Braintree_CreditCard::CreateSignature());
  }
  function testUpdateSignature() {
    $expected = array(
      'billingAddressId',
      'cardholderName',
      'cvv',
      'number',
      'expirationDate',
      'expirationMonth',
      'expirationYear',
      'token',
      array(
        'options' => array(
          'makeDefault',
          'verificationMerchantAccountId',
          'verifyCard',
        ),
      ),
      array(
        'billingAddress' => array(
          'firstName',
          'lastName',
          'company',
          'countryCodeAlpha2',
          'countryCodeAlpha3',
          'countryCodeNumeric',
          'countryName',
          'extendedAddress',
          'locality',
          'region',
          'postalCode',
          'streetAddress',
          array(
            'options' => array(
              'updateExisting',
            ),
          ),
        ),
      ),
    );
    $this
      ->assertEquals($expected, Braintree_CreditCard::UpdateSignature());
  }
  function testErrorsOnFindWithBlankArgument() {
    $this
      ->setExpectedException('InvalidArgumentException');
    Braintree_CreditCard::find('');
  }
  function testErrorsOnFindWithWhitespaceArgument() {
    $this
      ->setExpectedException('InvalidArgumentException');
    Braintree_CreditCard::find('  ');
  }
  function testErrorsOnFindWithWhitespaceCharacterArgument() {
    $this
      ->setExpectedException('InvalidArgumentException');
    Braintree_CreditCard::find('\\t');
  }

}

Members