You are here

public function UbercartCreditCardTestCase::testExpiryDate in Ubercart 7.3

Same name and namespace in other branches
  1. 6.2 payment/uc_credit/uc_credit.test \UbercartCreditCardTestCase::testExpiryDate()

Tests that expiry date validation functions correctly.

File

payment/uc_credit/tests/uc_credit.test, line 295
Credit card payment method tests.

Class

UbercartCreditCardTestCase
Tests credit card payments with the test gateway.

Code

public function testExpiryDate() {
  $order = $this
    ->createOrder(array(
    'payment_method' => 'credit',
  ));
  $year = date('Y');
  $month = date('n');
  for ($y = $year; $y <= $year + 2; $y++) {
    for ($m = 1; $m <= 12; $m++) {
      $edit = array(
        'amount' => 1,
        'cc_data[cc_number]' => '4111111111111111',
        'cc_data[cc_cvv]' => '123',
        'cc_data[cc_exp_month]' => $m,
        'cc_data[cc_exp_year]' => $y,
      );
      $this
        ->drupalPost('admin/store/orders/' . $order->order_id . '/credit', $edit, 'Charge amount');
      if ($y > $year || $m >= $month) {
        $this
          ->assertText('The credit card was processed successfully.', t('Card with expiry date @month/@year passed validation.', array(
          '@month' => $m,
          '@year' => $y,
        )));
      }
      else {
        $this
          ->assertNoText('The credit card was processed successfully.', t('Card with expiry date @month/@year correctly failed validation.', array(
          '@month' => $m,
          '@year' => $y,
        )));
      }
    }
  }
}