You are here

function ucRecurringTestCase::processRecurringFee in UC Recurring Payments and Subscriptions 6.2

Same name and namespace in other branches
  1. 7.2 uc_recurring.test \ucRecurringTestCase::processRecurringFee()

Process a recurring fee.

3 calls to ucRecurringTestCase::processRecurringFee()
ucRecurringAPITestCase::testRecurringAdminFunctions in ./uc_recurring.test
Test administrator functions.
ucRecurringAPITestCase::testRecurringOrders in ./uc_recurring.test
Test customer functions of purchasing an order with recurring product.
ucRecurringIntegrationTestCase::testRecurringPaymentIntegration in ./uc_recurring.test
place an order with the mock gateway payment module

File

./uc_recurring.test, line 107
UC Recurring simpletest

Class

ucRecurringTestCase
@file UC Recurring simpletest

Code

function processRecurringFee($rfid, $times_to_renew) {
  $old_fee = uc_recurring_fee_user_load($rfid);
  $current_order_id = empty($old_fee->data['recurring orders']) ? $old_fee->order_id : max($old_fee->data['recurring orders']);

  // Simulate the order being ready for renewal by changing the "next_charge"
  // field.
  db_query("UPDATE {uc_recurring_users} SET next_charge=%d WHERE rfid=%d", time() - 1, $rfid);

  // Run cron function.
  uc_recurring_cron();
  $new_order_id = $this
    ->lastCreatedOrderId();
  if ($old_fee->remaining_intervals == 0) {

    // There should be no new order.
    $this
      ->pass(t('Recurring Fee %rfid has expired', array(
      '%rfid' => $rfid,
    )));
  }
  else {
    $this
      ->pass(t('Order %order_id has been created', array(
      '%order_id' => $new_order_id,
    )));
    $fee = uc_recurring_fee_user_load($rfid);
    $this
      ->assertEqual($fee->charged_intervals, $old_fee->charged_intervals + 1, t('Number of intervals been charged is now: %charged.', array(
      '%charged' => $fee->charged_intervals,
    )));

    // Negative intervals means unlimited renewals.
    if ($old_fee->remaining_intervals < 0) {
      $this
        ->assertEqual($fee->remaining_intervals, -1, t('Still has unlimited intervals remaining.'));
    }
    else {
      $this
        ->assertEqual($fee->remaining_intervals, $old_fee->remaining_intervals - 1, t('%remaining_intervals remaining interval.', array(
        '%remaining_intervals' => $fee->remaining_intervals,
      )));
    }
    if ($times_to_renew > 1) {
      return $this
        ->processRecurringFee($rfid, $times_to_renew - 1);
    }
  }
}