You are here

function ucRecurringAPITestCase::testRecurringOrders in UC Recurring Payments and Subscriptions 6.2

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

Test customer functions of purchasing an order with recurring product.

File

./uc_recurring.test, line 167
UC Recurring simpletest

Class

ucRecurringAPITestCase
Test the recurring API.

Code

function testRecurringOrders() {
  $this
    ->drupalLogin($this->user_recurring_admin);

  // create two products with recurring features
  $product1 = $this
    ->createProduct();
  $p1_recurring_feature = $this
    ->createRecurringFeature($product1->nid, array(
    'unlimited_intervals' => TRUE,
  ));
  $product2 = $this
    ->createProduct();
  $p2_recurring_feature = $this
    ->createRecurringFeature($product2->nid);
  $this
    ->drupalLogout();

  // test logging in as an authenticated user
  // purchasing an order with a unlimited recurring fee
  // navigating to
  $this
    ->pass(t('Testing authenticated checkout.'));
  $this
    ->drupalLogin($this->user_recurring_customer);
  $order_id = $this
    ->placeOrderWithRecurringFee($product1);
  if ($order_id) {
    $this
      ->assertRaw('Your order is complete! Your order number is ' . $order_id . '.', t('The order id displayed on complete page'));

    // test that as a user can navigate around their account and view the order and recurring fee details
    $this
      ->clickLink(t('My account'));
    $this
      ->clickLink(t('Click here to view your recurring fees'));
    $this
      ->clickLink(t('!order_id', array(
      '!order_id' => $order_id,
    )));
    $this
      ->assertRaw('Order ' . $order_id, t('Viewing Order in the users account'));
    $fee = $this
      ->getSingleRecurringFeeFromOrder($order_id);
    $this
      ->processRecurringFee($fee->rfid, 2);

    // cancel order
    $this
      ->drupalGet('user');
    $this
      ->clickLink(t('Click here to view your recurring fees'));
    $this
      ->clickLink(t('cancel'));
    $this
      ->drupalPost(NULL, array(), t('Yes, I want to cancel the subscription'));
    $fee = uc_recurring_fee_user_load($fee->rfid);
    $this
      ->assertEqual($fee->remaining_intervals, 0, t('Recurring order !order_id canceled', array(
      '!order_id' => $order_id,
    )));

    // attempt to renew
    $last_order_id = $this
      ->lastCreatedOrderId();
    $this
      ->processRecurringFee($fee->rfid, 1);
    $this
      ->assertEqual($last_order_id, $this
      ->lastCreatedOrderId(), t('Order did not renew after canceled.'));
  }
  $this
    ->drupalLogout();
  $this
    ->pass(t('Testing anonymous checkout.'));
  $order_id = $this
    ->placeOrderWithRecurringFee($product2);
  if ($order_id) {
    $this
      ->pass(t('Order %order_id has been created', array(
      '%order_id' => $order_id,
    )));
    $fee = $this
      ->getSingleRecurringFeeFromOrder($order_id);
    $this
      ->processRecurringFee($fee->rfid, $p1_recurring_feature['number_intervals'] + 1);

    // attempt to renew
    $last_order_id = $this
      ->lastCreatedOrderId();
    $this
      ->processRecurringFee($fee->rfid, 1);
    $this
      ->assertEqual($last_order_id, $this
      ->lastCreatedOrderId(), t('Order did not renew after canceled.'));
  }
}