You are here

public function CommercePaymentCreditCardTest::testValidateNumber in Commerce Core 7

Tests type detection.

File

modules/payment/tests/commerce_payment_credit_card.test, line 35
Unit tests for credit card detection.

Class

CommercePaymentCreditCardTest
Tests credit card detection.

Code

public function testValidateNumber() {

  // Structure: Number, Type, Valid.
  $data = array(
    // Non-numeric value.
    array(
      'invalid',
      NULL,
      FALSE,
    ),
    // Invalid length.
    array(
      41111111111111111,
      'visa',
      FALSE,
    ),
    // Fails luhn check.
    array(
      41111111111111112,
      'visa',
      FALSE,
    ),
    // Valid numbers.
    array(
      4111111111111111,
      'visa',
      TRUE,
    ),
    array(
      6759649826438453,
      'maestro',
      TRUE,
    ),
    array(
      3528000700000000,
      'jcb',
      TRUE,
    ),
    array(
      5555555555554444,
      'mastercard',
      TRUE,
    ),
    array(
      36700102000000,
      'dc',
      TRUE,
    ),
    array(
      30569309025904,
      'dc',
      TRUE,
    ),
    array(
      38520000023237,
      'dc',
      TRUE,
    ),
    array(
      6011000400000000,
      'discover',
      TRUE,
    ),
    array(
      6208205838887174,
      'unionpay',
      TRUE,
    ),
    array(
      374251018720018,
      'amex',
      TRUE,
    ),
    // Visa Electron card.
    array(
      4917300800000000,
      'visa',
      TRUE,
    ),
  );
  foreach ($data as $datum) {
    $type = CommercePaymentCreditCard::detectType($datum[0]);
    if (!$type) {
      $this
        ->assertEqual(NULL, $datum[1]);
    }
    else {
      $this
        ->assertEqual($type['id'], $datum[1]);
      $this
        ->assertEqual($datum[2], CommercePaymentCreditCard::validateNumber($datum[0], $type));
    }
  }
}