You are here

class ucRecurringAPITestCase in UC Recurring Payments and Subscriptions 7.2

Same name and namespace in other branches
  1. 6.2 uc_recurring.test \ucRecurringAPITestCase

Test the recurring API.

Hierarchy

Expanded class hierarchy of ucRecurringAPITestCase

File

./uc_recurring.test, line 156
UC Recurring simpletest

View source
class ucRecurringAPITestCase extends ucRecurringTestCase {
  public static function getInfo() {
    return array(
      'name' => t('API functions'),
      'description' => t('Setup recurring product and test the actions that can occur on a recurring payment.'),
      'group' => t('Ubercart recurring fees'),
    );
  }
  function setUp() {
    parent::setUp('uc_recurring', 'uc_recurring_product');
    $this
      ->createRecurringUsers();
  }

  /**
   * Test customer functions of purchasing an order with recurring product.
   */
  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.'));
    }
  }

  /**
   * Test administrator functions.
   */
  function testRecurringAdminFunctions() {
    $this
      ->drupalLogin($this->user_recurring_admin);
    $this
      ->drupalGet('admin/store/orders/recurring');

    // TODO: check admin settings form
    // create two products with recurring features
    $product = $this
      ->createProduct();
    $recurring_feature = $this
      ->createRecurringFeature($product->nid);
    $this
      ->drupalLogout();

    // create an order
    $order_id = $this
      ->placeOrderWithRecurringFee($product);
    if ($order_id) {
      $order = uc_order_load($order_id);
      $fees = uc_recurring_get_fees($order);
      $fee = $fees[0];
      $this
        ->drupalLogin($this->user_recurring_admin);

      // charge fee
      $this
        ->drupalGet('admin/store/orders/recurring');
      $this
        ->clickLink(t('charge'));
      $this
        ->drupalPost(NULL, array(), t('Process Renewal'));
      $this
        ->assertEqual($order_id + 1, $this
        ->lastCreatedOrderId(), t('Order renewed after canceled.'));

      // edit fee
      $this
        ->drupalGet('admin/store/orders/recurring');
      $this
        ->clickLink(t('edit'));

      // TODO: check we can edit fields and that they are updated in db
      // cancel fee
      $this
        ->drupalGet('admin/store/orders/recurring');
      $this
        ->clickLink(t('cancel'));
      $this
        ->drupalPost(NULL, array(), t('Yes, I want to cancel the subscription'));

      // 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();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ucRecurringAPITestCase::getInfo public static function
ucRecurringAPITestCase::setUp function
ucRecurringAPITestCase::testRecurringAdminFunctions function Test administrator functions.
ucRecurringAPITestCase::testRecurringOrders function Test customer functions of purchasing an order with recurring product.
ucRecurringTestCase::createRecurringFeature function Add a recurring feature to a product.
ucRecurringTestCase::createRecurringUsers function Create users with recurring permissions.
ucRecurringTestCase::getSingleRecurringFeeFromOrder function Get a single recurring fee from the order ID.
ucRecurringTestCase::lastCreatedOrderId function Returns the last order_id added in the database.
ucRecurringTestCase::placeOrderWithRecurringFee function place an order for a product with a recurring fee.
ucRecurringTestCase::processRecurringFee function Process a recurring fee.