You are here

function ucRecurringIntegrationTestCase::testRecurringPaymentIntegration in UC Recurring Payments and Subscriptions 7.2

Same name and namespace in other branches
  1. 6.2 uc_recurring.test \ucRecurringIntegrationTestCase::testRecurringPaymentIntegration()

place an order with the mock gateway payment module

File

./uc_recurring.test, line 301
UC Recurring simpletest

Class

ucRecurringIntegrationTestCase
Test payment gateway API functions in uc_recurring.

Code

function testRecurringPaymentIntegration() {
  global $gateway_status;
  $gateway_status = TRUE;
  $this
    ->drupalLogin($this->user_recurring_admin);
  $checkoutMessage = $this
    ->randomName(20);

  // select mock gateway for payments
  $settings = array(
    'uc_recurring_payment_methods[mock_gateway]' => TRUE,
    'uc_recurring_checkout_message' => $checkoutMessage,
  );
  $this
    ->drupalPost('admin/store/settings/payment/edit/recurring', $settings, t('Save configuration'));

  // create products with recurring features
  $product = $this
    ->createProduct();
  $recurring_feature = $this
    ->createRecurringFeature($product->nid, array(
    'unlimited_intervals' => TRUE,
  ));
  $this
    ->drupalLogout();
  $order_id = $this
    ->placeOrderWithRecurringFee($product);
  if ($order_id) {
    $fee = $this
      ->getSingleRecurringFeeFromOrder($order_id);
    $order = uc_order_load($order_id);
    $this
      ->assertTrue(uc_payment_balance($order) <= 0, t('Order @order_id payment processed', array(
      '@order_id' => $order_id,
    )));

    // test renewal on successful payment processing
    $this
      ->processRecurringFee($fee->rfid, 1);
    $order = uc_order_load($this
      ->lastCreatedOrderId());
    $this
      ->assertTrue(uc_payment_balance($order) <= 0, t('Order @order_id payment processed', array(
      '@order_id' => $order->order_id,
    )));

    // order should now be completed
    // test renewal on failed payment processing
    $gateway_status = FALSE;
    $current_order_id = $this
      ->lastCreatedOrderId();
    $this
      ->processRecurringFee($fee->rfid, 1);
    $order = uc_order_load($this
      ->lastCreatedOrderId());
    $this
      ->assertEqual($order->order_id, $current_order_id, t('No new order created on failed payment'));
  }
}