You are here

class CommerceRecurringTestCase in Commerce Recurring Framework 7.2

@file Unit tests for the commerce recurring module.

Hierarchy

Expanded class hierarchy of CommerceRecurringTestCase

File

tests/commerce_recurring.test, line 7
Unit tests for the commerce recurring module.

View source
class CommerceRecurringTestCase extends CommerceBaseTestCase {

  /**
   * @var stdClass
   * User for the testing.
   */
  private $customer = NULL;

  /**
   * getInfo() returns properties that are displayed in the test selection form.
   */
  public static function getInfo() {
    return array(
      'name' => t('Commerce recurring'),
      'description' => t('Commerce recurring tests.'),
      'group' => t('Commerce recurring'),
    );
  }

  /**
   * setUp() performs any pre-requisite tasks that need to happen.
   */
  public function setUp() {
    $other_modules = array(
      'interval',
      'entityreference',
      'date',
      'date_popup',
      'commerce_recurring',
    );
    $modules = parent::setUpHelper('all', $other_modules);
    parent::setUp($modules);
    $this->customer = $this
      ->createStoreCustomer();
    cache_clear_all();

    // Just in case
  }

  /**
   * Creates a recurring product for use with other tests.
   * @return
   *  A product with most of it's basic fields set random values.
   *  FALSE if the appropiate modules were not available.
   */
  public function createRecurringProduct() {
    $new_product = commerce_product_new('recurring');
    $new_product->sku = $this
      ->randomName(10);
    $new_product->title = $this
      ->randomName(10);
    $new_product->uid = 1;
    $period = array();

    // Set prices.
    $new_product->commerce_price[LANGUAGE_NONE][0]['amount'] = rand(200, 50000);
    $new_product->commerce_price[LANGUAGE_NONE][0]['currency_code'] = 'USD';
    $new_product->commerce_recurring_ini_price[LANGUAGE_NONE][0]['amount'] = rand(200, 50000);
    $new_product->commerce_recurring_ini_price[LANGUAGE_NONE][0]['currency_code'] = 'USD';
    $new_product->commerce_recurring_rec_price[LANGUAGE_NONE][0]['amount'] = rand(200, 50000);
    $new_product->commerce_recurring_rec_price[LANGUAGE_NONE][0]['currency_code'] = 'USD';

    // Set intervals.
    foreach (array(
      'commerce_recurring_ini_period',
      'commerce_recurring_rec_period',
      'commerce_recurring_end_period',
    ) as $field_name) {
      $instance = field_info_instance('commerce_product', $field_name, 'recurring');
      $period[] = array_rand($instance['settings']['allowed_periods'], 1);
    }
    $new_product->commerce_recurring_ini_period[LANGUAGE_NONE][0]['interval'] = rand(2, 25);
    $new_product->commerce_recurring_ini_period[LANGUAGE_NONE][0]['period'] = $period[0];
    $new_product->commerce_recurring_rec_period[LANGUAGE_NONE][0]['interval'] = rand(2, 25);
    $new_product->commerce_recurring_rec_period[LANGUAGE_NONE][0]['period'] = $period[0];
    $new_product->commerce_recurring_end_period[LANGUAGE_NONE][0]['interval'] = rand(2, 25);
    $new_product->commerce_recurring_end_period[LANGUAGE_NONE][0]['period'] = $period[0];
    commerce_product_save($new_product);
    return $new_product;
  }

  /**
   * Creates a recurring entity to be used in other tests.
   * @param entity $product
   *   Commerce Product assigned to the Recurring entity.
   * @param int $quantity
   *   Quantity of the product.
   * @param int $start_date
   *   Initial date for recurring.
   * @param int $due_date
   *   Due date for recurring.
   * @param int $end_date
   *   End date for recurring.
   *
   * @return bool A recurring entity with fields configured randomly unless they're
   */
  public function createRecurringEntity($product = NULL, $quantity = 1, $start_date = NULL, $due_date = NULL, $end_date = NULL) {
    if (empty($product)) {
      $product = $this
        ->createRecurringProduct();
    }
    $line_item = commerce_cart_product_add_by_id($product->product_id, 1, TRUE, $this->customer->uid);
    if (empty($start_date)) {
      $start_date = new DateObject('2010-01-01');
    }
    if (empty($due_date)) {
      $due_date = new DateObject();
      $due_date
        ->sub(new DateInterval('P1D'));
    }

    // Create the recurring entity faking the dates to be due.
    $values = array(
      'type' => 'product',
      'product_id' => $product->product_id,
      'order_ids' => array(
        $line_item->order_id,
      ),
      'start_date' => $start_date
        ->getTimestamp(),
      'due_date' => $due_date
        ->getTimestamp(),
      'end_date' => !empty($end_date) ? $end_date
        ->getTimestamp() : NULL,
      'uid' => $this->customer->uid,
      'quantity' => isset($quantity) ? $quantity : 1,
    );
    $recurring_entity = commerce_recurring_new($values);
    entity_save('commerce_recurring', $recurring_entity);
    return $recurring_entity;
  }

  /**
   * Test creating a recurring product.
   */
  function testCreateRecurringProduct() {
    $store_admin = $this
      ->createStoreAdmin();
    $this
      ->drupalLogin($store_admin);
    $this
      ->drupalGet('admin/commerce/products/add/recurring');
    foreach (array(
      'commerce_recurring_ini_period',
      'commerce_recurring_rec_period',
      'commerce_recurring_end_period',
    ) as $field_name) {
      $instance = field_info_instance('commerce_product', $field_name, 'recurring');
      $period[] = array_rand($instance['settings']['allowed_periods'], 1);
    }

    // Create the recurring product.
    $edit = array(
      'sku' => 'PROD-01',
      'title' => $this
        ->randomName(10),
      'commerce_price[und][0][amount]' => commerce_currency_amount_to_decimal(rand(200, 50000), 'USD'),
      'commerce_recurring_ini_price[und][0][amount]' => commerce_currency_amount_to_decimal(rand(200, 50000), 'USD'),
      'commerce_recurring_rec_price[und][0][amount]' => commerce_currency_amount_to_decimal(rand(200, 50000), 'USD'),
      'commerce_recurring_ini_period[und][0][interval]' => rand(2, 10),
      'commerce_recurring_ini_period[und][0][period]' => $period[0],
      'commerce_recurring_rec_period[und][0][interval]' => rand(2, 10),
      'commerce_recurring_rec_period[und][0][period]' => $period[1],
      'commerce_recurring_end_period[und][0][interval]' => rand(2, 10),
      'commerce_recurring_end_period[und][0][period]' => $period[2],
      'status' => 1,
    );
    $this
      ->drupalPost(NULL, $edit, t('Save product'));
    $this
      ->assertText(t('Product saved.'), t('%message message is present', array(
      '%message' => t('Product saved'),
    )));
    $this
      ->assertText(t('Recurring product'), t('Recurring product type name found after creating a product of that type'));

    // Check the product in database.
    $product = commerce_product_load_by_sku($edit['sku']);
    $product_wrapper = entity_metadata_wrapper('commerce_product', $product);
    $this
      ->pass(t('Test the product edit in database:'));
    $this
      ->assertTrue($product_wrapper->sku
      ->value() == $edit['sku'], t('SKU stored in database correctly set'));
    $this
      ->assertTrue($product_wrapper->title
      ->value() == $edit['title'], t('Title stored in database correctly set'));
    $this
      ->assertTrue(commerce_currency_amount_to_decimal($product_wrapper->commerce_price->amount
      ->value(), $product_wrapper->commerce_price->currency_code
      ->value()) == $edit['commerce_price[und][0][amount]'], t('Amount stored in database correctly set'));
    $this
      ->assertTrue($product->status == $edit['status'], t('Status stored in database correctly set'));
    $this
      ->assertTrue(commerce_currency_amount_to_decimal($product_wrapper->commerce_recurring_ini_price->amount
      ->value(), $product_wrapper->commerce_recurring_ini_price->currency_code
      ->value()) == $edit['commerce_recurring_ini_price[und][0][amount]'], t('Initial amount stored in database correctly set'));
    $this
      ->assertTrue(commerce_currency_amount_to_decimal($product_wrapper->commerce_recurring_rec_price->amount
      ->value(), $product_wrapper->commerce_recurring_rec_price->currency_code
      ->value()) == $edit['commerce_recurring_rec_price[und][0][amount]'], t('Recurring amount stored in database correctly set'));
    $this
      ->assertTrue($product_wrapper->commerce_recurring_ini_period->interval
      ->value() == $edit['commerce_recurring_ini_period[und][0][interval]'], t('Initial period stored in database correctly set'));
    $this
      ->assertTrue($product_wrapper->commerce_recurring_ini_period->period
      ->value() == $edit['commerce_recurring_ini_period[und][0][period]'], t('Initial interval stored in database correctly set'));
    $this
      ->assertTrue($product_wrapper->commerce_recurring_rec_period->interval
      ->value() == $edit['commerce_recurring_rec_period[und][0][interval]'], t('Initial period stored in database correctly set'));
    $this
      ->assertTrue($product_wrapper->commerce_recurring_rec_period->period
      ->value() == $edit['commerce_recurring_rec_period[und][0][period]'], t('Initial interval stored in database correctly set'));
    $this
      ->assertTrue($product_wrapper->commerce_recurring_end_period->interval
      ->value() == $edit['commerce_recurring_end_period[und][0][interval]'], t('Initial period stored in database correctly set'));
    $this
      ->assertTrue($product_wrapper->commerce_recurring_end_period->period
      ->value() == $edit['commerce_recurring_end_period[und][0][period]'], t('Initial interval stored in database correctly set'));
  }

  /**
   * Create a Recurring entity.
   */
  function testCommerceRecurringEntityCreation() {
    $product = $this
      ->createRecurringProduct();
    $line_item = commerce_cart_product_add_by_id($product->product_id);
    $order = commerce_order_load($line_item->order_id);
    $recurring_entity = commerce_recurring_new_from_product($order, $product, $line_item->commerce_unit_price[LANGUAGE_NONE][0], $line_item->quantity);
    entity_save('commerce_recurring', $recurring_entity);
    $recurring_entity_load = entity_load_single('commerce_recurring', $recurring_entity->id);
    $this
      ->assertTrue($recurring_entity->id == 1, t('Recurring entity has generated an id.'));
    $this
      ->assertEqual($recurring_entity_load->commerce_recurring_ref_product[LANGUAGE_NONE][0]['target_id'], $recurring_entity->commerce_recurring_ref_product[LANGUAGE_NONE][0]['target_id'], t('Product values correctly set for the recurring entity saved.'));
    $this
      ->assertEqual($recurring_entity_load->commerce_recurring_order[LANGUAGE_NONE][0]['target_id'], $recurring_entity->commerce_recurring_order[LANGUAGE_NONE][0]['target_id'], t('Order values correctly set for the recurring entity saved.'));
  }

  /**
   * When creating an order and finish a payment, recurring entity
   */
  function testCommerceRecurringEntityCreationWorkflow() {

    // Login as a customer to proceed with the order.
    $this
      ->drupalLogin($this->customer);

    // Add a product to the cart and go on in checkout.
    $product = $this
      ->createRecurringProduct();
    $product_wrapper = entity_metadata_wrapper('commerce_product', $product);
    $line_item = commerce_cart_product_add_by_id($product->product_id, 1, TRUE, $this->customer->uid);
    $this
      ->drupalPost($this
      ->getCommerceUrl('cart'), array(), t('Checkout'));

    // Generate random information, as city, postal code, etc.
    $address_info = $this
      ->generateAddressInformation();

    // Fill in the billing address information.
    $billing_pane = $this
      ->xpath("//select[starts-with(@name, 'customer_profile_billing[commerce_customer_address]')]");
    $this
      ->drupalPostAJAX(NULL, array(
      (string) $billing_pane[0]['name'] => 'US',
    ), (string) $billing_pane[0]['name']);

    // Fill in the required information for billing pane, with a random State.
    $info = array(
      'customer_profile_billing[commerce_customer_address][und][0][name_line]' => $address_info['name_line'],
      'customer_profile_billing[commerce_customer_address][und][0][thoroughfare]' => $address_info['thoroughfare'],
      'customer_profile_billing[commerce_customer_address][und][0][locality]' => $address_info['locality'],
      'customer_profile_billing[commerce_customer_address][und][0][administrative_area]' => 'KY',
      'customer_profile_billing[commerce_customer_address][und][0][postal_code]' => $address_info['postal_code'],
    );
    $this
      ->drupalPost(NULL, $info, t('Continue to next step'));

    // Finish checkout process
    $this
      ->drupalPost(NULL, array(
      'commerce_payment[payment_method]' => 'commerce_payment_example|commerce_payment_commerce_payment_example',
    ), t('Continue to next step'));

    // Load recurring entities.
    $order = commerce_order_load($line_item->order_id);
    $recurring_entities = commerce_recurring_load_by_order($order);
    $recurring_entity = reset($recurring_entities);
    $recurring_wrapper = entity_metadata_wrapper('commerce_recurring', $recurring_entity);

    // Gather expected dates.
    $start_date = $recurring_wrapper->start_date
      ->value();
    $due_date = new DateObject($start_date);
    $end_date = new DateObject($start_date);
    $initial_interval = $product_wrapper->commerce_recurring_ini_period
      ->value();
    $end_interval = $product_wrapper->commerce_recurring_end_period
      ->value();
    interval_apply_interval($due_date, $initial_interval, TRUE);
    interval_apply_interval($end_date, $end_interval, TRUE);

    // Assert if the recurring entity is being created as expected.
    $this
      ->assertEqual($recurring_wrapper->commerce_recurring_ref_product
      ->value(), $product, t('Product is correctly set in the recurring entity'));
    $this
      ->assertEqual($recurring_wrapper->commerce_recurring_order
      ->get(0)->order_id
      ->value(), $order->order_id, t('Order is correctly set in the recurring entity'));
    $this
      ->assertEqual($recurring_wrapper->commerce_recurring_fixed_price->amount
      ->value(), $product_wrapper->commerce_recurring_ini_price->amount
      ->value(), t('Initial price is correctly set for the recurring entity'));
    $this
      ->assertEqual($recurring_wrapper->due_date
      ->value(), $due_date
      ->getTimestamp(), t('Recurring date is set for the recurring entity'));
    $this
      ->assertEqual($recurring_wrapper->end_date
      ->value(), $end_date
      ->getTimestamp(), t('End date is set for the recurring entity'));
  }

  /**
   * Test workflow with no initial date.
   */
  function testCommerceRecurringEntityCreationWorkflowNoInitialDate() {

    // Login as a customer to proceed with the order.
    $this
      ->drupalLogin($this->customer);

    // Add a product to the cart without initial period.
    $product = commerce_product_new('recurring');
    $product->sku = $this
      ->randomName(10);
    $product->title = $this
      ->randomName(10);
    $product->uid = 1;
    $period = array();

    // Set prices.
    $product->commerce_price[LANGUAGE_NONE][0]['amount'] = rand(200, 50000);
    $product->commerce_price[LANGUAGE_NONE][0]['currency_code'] = 'USD';
    $product->commerce_recurring_ini_price[LANGUAGE_NONE][0]['amount'] = rand(200, 50000);
    $product->commerce_recurring_ini_price[LANGUAGE_NONE][0]['currency_code'] = 'USD';
    $product->commerce_recurring_rec_price[LANGUAGE_NONE][0]['amount'] = rand(200, 50000);
    $product->commerce_recurring_rec_price[LANGUAGE_NONE][0]['currency_code'] = 'USD';

    // Set intervals.
    foreach (array(
      'commerce_recurring_ini_period',
      'commerce_recurring_rec_period',
      'commerce_recurring_end_period',
    ) as $field_name) {
      $instance = field_info_instance('commerce_product', $field_name, 'recurring');
      $period[] = array_rand($instance['settings']['allowed_periods'], 1);
    }
    $product->commerce_recurring_rec_period[LANGUAGE_NONE][0]['interval'] = rand(2, 25);
    $product->commerce_recurring_rec_period[LANGUAGE_NONE][0]['period'] = $period[0];
    $product->commerce_recurring_end_period[LANGUAGE_NONE][0]['interval'] = rand(2, 25);
    $product->commerce_recurring_end_period[LANGUAGE_NONE][0]['period'] = $period[0];
    commerce_product_save($product);
    $product_wrapper = entity_metadata_wrapper('commerce_product', $product);
    $line_item = commerce_cart_product_add_by_id($product->product_id, 1, TRUE, $this->customer->uid);
    $this
      ->drupalPost($this
      ->getCommerceUrl('cart'), array(), t('Checkout'));

    // Generate random information, as city, postal code, etc.
    $address_info = $this
      ->generateAddressInformation();

    // Fill in the billing address information.
    $billing_pane = $this
      ->xpath("//select[starts-with(@name, 'customer_profile_billing[commerce_customer_address]')]");
    $this
      ->drupalPostAJAX(NULL, array(
      (string) $billing_pane[0]['name'] => 'US',
    ), (string) $billing_pane[0]['name']);

    // Fill in the required information for billing pane, with a random State.
    $info = array(
      'customer_profile_billing[commerce_customer_address][und][0][name_line]' => $address_info['name_line'],
      'customer_profile_billing[commerce_customer_address][und][0][thoroughfare]' => $address_info['thoroughfare'],
      'customer_profile_billing[commerce_customer_address][und][0][locality]' => $address_info['locality'],
      'customer_profile_billing[commerce_customer_address][und][0][administrative_area]' => 'KY',
      'customer_profile_billing[commerce_customer_address][und][0][postal_code]' => $address_info['postal_code'],
    );
    $this
      ->drupalPost(NULL, $info, t('Continue to next step'));

    // Finish checkout process
    $this
      ->drupalPost(NULL, array(
      'commerce_payment[payment_method]' => 'commerce_payment_example|commerce_payment_commerce_payment_example',
    ), t('Continue to next step'));

    // Load recurring entities.
    $order = commerce_order_load($line_item->order_id);
    $recurring_entities = commerce_recurring_load_by_order($order);
    $recurring_entity = reset($recurring_entities);
    $recurring_wrapper = entity_metadata_wrapper('commerce_recurring', $recurring_entity);

    // Gather expected dates.
    $start_date = $recurring_wrapper->start_date
      ->value();
    $due_date = new DateObject($start_date);
    $end_date = new DateObject($start_date);
    $initial_interval = $product_wrapper->commerce_recurring_rec_period
      ->value();
    $end_interval = $product_wrapper->commerce_recurring_end_period
      ->value();
    interval_apply_interval($due_date, $initial_interval, TRUE);
    interval_apply_interval($end_date, $end_interval, TRUE);

    // Assert if the recurring entity is being created as expected.
    $this
      ->assertEqual($recurring_wrapper->commerce_recurring_ref_product
      ->value(), $product, t('Product is correctly set in the recurring entity'));
    $this
      ->assertEqual($recurring_wrapper->commerce_recurring_order
      ->get(0)->order_id
      ->value(), $order->order_id, t('Order is correctly set in the recurring entity'));
    $this
      ->assertEqual($recurring_wrapper->commerce_recurring_fixed_price->amount
      ->value(), $product_wrapper->commerce_recurring_ini_price->amount
      ->value(), t('Initial price is correctly set for the recurring entity'));
    $this
      ->assertEqual($recurring_wrapper->due_date
      ->value(), $due_date
      ->getTimestamp(), t('Recurring date is set for the recurring entity'));
    $this
      ->assertEqual($recurring_wrapper->end_date
      ->value(), $end_date
      ->getTimestamp(), t('End date is set for the recurring entity'));
  }

  /**
   * Test cron run and order creation on recurring entity date base.
   */
  function testCommerceRecurringCronOrderCreation() {

    // Create a recurring entity.
    $product = $this
      ->createRecurringProduct();
    $product_wrapper = entity_metadata_wrapper('commerce_product', $product);
    $line_item = commerce_cart_product_add_by_id($product->product_id, 1, TRUE, $this->customer->uid);
    $recurring_entity = $this
      ->createRecurringEntity($product);
    $initial_order = commerce_order_load($line_item->order_id);
    $initial_order->commerce_customer_billing = (array) $this
      ->createDummyCustomerProfile('billing', $this->customer->uid);
    $initial_order->status = 'completed';
    commerce_order_save($initial_order);
    commerce_cart_order_ids_reset();

    // Run cron.
    drupal_cron_run();

    // Check if the order has been correctly created and it's linked to the
    // recurring entity.
    $recurring_entities = entity_load('commerce_recurring', array(
      $recurring_entity->id,
    ), array(), TRUE);
    $recurring_entity = reset($recurring_entities);
    $recurring_wrapper = entity_metadata_wrapper('commerce_recurring', $recurring_entity);

    // The order is the second one now.
    $order_wrapper = $recurring_wrapper->commerce_recurring_order
      ->get(1);
    $order = $order_wrapper
      ->value();
    $this
      ->assertTrue(isset($order), t('New order has been created for the recurring entity'));
    $this
      ->assertEqual($order->data['recurring_entity'], $recurring_entity->id, t('Recurring id is associated with the order'));
    $this
      ->assertEqual($order_wrapper->commerce_order_total->amount
      ->value(), $product_wrapper->commerce_recurring_rec_price->amount
      ->value(), t('Total price is calculated ok'));
    $this
      ->assertEqual($order->status, 'recurring_pending', t('Order is created in recurring_pending status'));
    $first_order = $recurring_wrapper->commerce_recurring_order
      ->get(0)
      ->value();
    $this
      ->assertEqual($order->commerce_customer_billing, $first_order->commerce_customer_billing, t('Customer profile information gets copied from the initial order to the recurring one'));
    $user_current_cart = commerce_cart_order_load($this->customer->uid);
    $this
      ->assertTrue(empty($user_current_cart), t('Customer cart is empty after creating a recurring order'));
  }

  /**
   * Test recurring entity update when orders created in cron are processed.
   */
  function testCommerceRecurringUpdateRecurringEntity() {

    // Create a recurring entity.
    $product = $this
      ->createRecurringProduct();
    $line_item = commerce_cart_product_add_by_id($product->product_id, 1, TRUE, $this->customer->uid);
    $start_date = new DateObject('2010-01-01');
    $due_date = new DateObject();
    $due_date
      ->sub(new DateInterval('P1D'));
    $recurring_entity = $this
      ->createRecurringEntity($product, 1, $start_date, $due_date);
    $initial_order = commerce_order_load($line_item->order_id);
    $initial_order->commerce_customer_billing = (array) $this
      ->createDummyCustomerProfile('billing', $this->customer->uid);
    $initial_order->status = 'completed';
    commerce_order_save($initial_order);

    // Run cron.
    drupal_cron_run();

    // Check if the order has been correctly created and it's linked to the
    // recurring entity.
    $recurring_entities = entity_load('commerce_recurring', array(
      $recurring_entity->id,
    ), array(), TRUE);
    $recurring_entity = reset($recurring_entities);
    $recurring_wrapper = entity_metadata_wrapper('commerce_recurring', $recurring_entity);

    // The order is the second one now.
    $order = $recurring_wrapper->commerce_recurring_order
      ->get(1)
      ->value();

    // Mock a payment that triggers Paid in full event.
    $payment_method = array(
      'instance_id' => 'commerce_payment_example',
    );
    $charge = array(
      'amount' => $order->commerce_order_total[LANGUAGE_NONE][0]['amount'],
      'currency_code' => $order->commerce_order_total[LANGUAGE_NONE][0]['currency_code'],
    );

    // Accomodate the default payment example order data values.
    $number = '4111111111111111';
    $order->data['commerce_payment_example'] = array(
      'credit_card' => array(
        'number' => substr($number, 0, 4) . str_repeat('-', strlen($number) - 8) . substr($number, -4),
        'exp_month' => date('m'),
        'exp_year' => date('Y'),
      ),
    );
    commerce_payment_example_transaction($payment_method, $order, $charge, 'Test payment');
    $recurring_entities = entity_load('commerce_recurring', array(
      $order->data['recurring_entity'],
    ), array(), TRUE);
    $reloaded_recurring_entity = reset($recurring_entities);
    $reloaded_recurring_entity_wrapper = entity_metadata_wrapper('commerce_recurring', $reloaded_recurring_entity);

    // Check if the recurring entity has been updated correctly.
    $this
      ->assertTrue(in_array($order->order_id, $reloaded_recurring_entity_wrapper->commerce_recurring_order
      ->raw()), t('Order is associated with the recurring entity.'));
    $count_values = array_count_values($reloaded_recurring_entity_wrapper->commerce_recurring_order
      ->raw());
    $this
      ->assertEqual($count_values[$order->order_id], 1, t('Order is associated once with the recurring entity.'));

    // Due date needs to be updated to the next recurring period.
    $product_wrapper = $reloaded_recurring_entity_wrapper->commerce_recurring_ref_product;
    $recurring_interval = $product_wrapper->commerce_recurring_rec_period
      ->value();
    interval_apply_interval($due_date, $recurring_interval, TRUE);
    $this
      ->assertEqual($due_date
      ->getTimestamp(), $reloaded_recurring_entity_wrapper->due_date
      ->value(), t('Recurring due date is correct.'));
  }

  /**
   * Test recurring entity end date.
   */
  function testCommerceRecurringEndDate() {

    // Create a recurring entity.
    $product = $this
      ->createRecurringProduct();
    $line_item = commerce_cart_product_add_by_id($product->product_id, 1, TRUE, $this->customer->uid);
    $start_date = new DateObject('2010-01-01');
    $due_date = new DateObject();
    $due_date
      ->sub(new DateInterval('P1D'));

    // Set the end date to be 1H before now.
    $end_date = new DateObject();
    $end_date
      ->sub(new DateInterval('PT1H'));
    $recurring_entity = $this
      ->createRecurringEntity($product, 1, $start_date, $due_date, $end_date);
    $initial_order = commerce_order_load($line_item->order_id);
    $initial_order->commerce_customer_billing = (array) $this
      ->createDummyCustomerProfile('billing', $this->customer->uid);
    $initial_order->status = 'completed';
    commerce_order_save($initial_order);

    // Run cron.
    drupal_cron_run();
    $recurring_entities = entity_load('commerce_recurring', array(
      $recurring_entity->id,
    ), array(), TRUE);
    $recurring_entity = reset($recurring_entities);
    $recurring_wrapper = entity_metadata_wrapper('commerce_recurring', $recurring_entity);
    $count_values = count($recurring_wrapper->commerce_recurring_order
      ->raw());
    $this
      ->assertEqual($count_values, 1, t('Second order was not generated at cron as the end date is in the past.'));
    $this
      ->assertEqual($recurring_entity->status, 0, t('Recurring entity has been disabled.'));
  }

  /**
   * Test adding a regular product so it shouldn't recur.
   */
  function testCommmerceRecurringRegularProduct() {
    $this
      ->drupalLogin($this->customer);
    $order = $this
      ->createDummyOrder($this->customer->uid);
    $this
      ->drupalPost($this
      ->getCommerceUrl('cart'), array(), t('Checkout'));

    // Generate random information, as city, postal code, etc.
    $address_info = $this
      ->generateAddressInformation();

    // Fill in the billing address information.
    $billing_pane = $this
      ->xpath("//select[starts-with(@name, 'customer_profile_billing[commerce_customer_address]')]");
    $this
      ->drupalPostAJAX(NULL, array(
      (string) $billing_pane[0]['name'] => 'US',
    ), (string) $billing_pane[0]['name']);

    // Fill in the required information for billing pane, with a random State.
    $info = array(
      'customer_profile_billing[commerce_customer_address][und][0][name_line]' => $address_info['name_line'],
      'customer_profile_billing[commerce_customer_address][und][0][thoroughfare]' => $address_info['thoroughfare'],
      'customer_profile_billing[commerce_customer_address][und][0][locality]' => $address_info['locality'],
      'customer_profile_billing[commerce_customer_address][und][0][administrative_area]' => 'KY',
      'customer_profile_billing[commerce_customer_address][und][0][postal_code]' => $address_info['postal_code'],
    );
    $this
      ->drupalPost(NULL, $info, t('Continue to next step'));

    // Finish checkout process
    $this
      ->drupalPost(NULL, array(
      'commerce_payment[payment_method]' => 'commerce_payment_example|commerce_payment_commerce_payment_example',
    ), t('Continue to next step'));
    $orders = commerce_order_load_multiple(array(
      $order->order_id,
    ), array(), TRUE);
    $order = reset($orders);
    $this
      ->assertEqual(array(), commerce_recurring_load_by_order($order), t('No recurring entities associated with the order.'));
  }

  /**
   * Test anonymous behaviour. Existing user
   */
  function testCommerceRecurringAnonymousOrderExistingUser() {
    $recurring_product = $this
      ->createRecurringProduct();
    $this
      ->createDummyProductDisplayContentType('product_display', TRUE, 'field_product', FIELD_CARDINALITY_UNLIMITED);
    $node = $this
      ->createDummyProductNode(array(
      $recurring_product->product_id,
    ));
    user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
      'access checkout' => TRUE,
    ));

    // Ensure we're not logged in.
    $this
      ->drupalLogout();

    // Override user variable to get the enviroment fully set.
    global $user;
    $user = user_load(0);

    // Submit the add to cart form.
    $this
      ->drupalPost('node/' . $node->nid, array(), t('Add to cart'));

    // Get the order for the anonymous user.
    $orders = commerce_order_load_multiple(array(), array(
      'uid' => $user->uid,
      'status' => 'cart',
    ), TRUE);
    $order = reset($orders);

    // Reset the cache as we don't want to keep the lock.
    entity_get_controller('commerce_order')
      ->resetCache();
    $this
      ->drupalPost($this
      ->getCommerceUrl('cart'), array(), t('Checkout'));

    // Generate random information, as city, postal code, etc.
    $address_info = $this
      ->generateAddressInformation();

    // Fill in the billing address information.
    $billing_pane = $this
      ->xpath("//select[starts-with(@name, 'customer_profile_billing[commerce_customer_address]')]");
    $this
      ->drupalPostAJAX(NULL, array(
      (string) $billing_pane[0]['name'] => 'US',
    ), (string) $billing_pane[0]['name']);

    // Fill in the required information for billing pane, with a random State.
    $info = array(
      'account[login][mail]' => $this->customer->mail,
      'customer_profile_billing[commerce_customer_address][und][0][name_line]' => $address_info['name_line'],
      'customer_profile_billing[commerce_customer_address][und][0][thoroughfare]' => $address_info['thoroughfare'],
      'customer_profile_billing[commerce_customer_address][und][0][locality]' => $address_info['locality'],
      'customer_profile_billing[commerce_customer_address][und][0][administrative_area]' => 'KY',
      'customer_profile_billing[commerce_customer_address][und][0][postal_code]' => $address_info['postal_code'],
    );
    $this
      ->drupalPost(NULL, $info, t('Continue to next step'));

    // Finish checkout process
    $this
      ->drupalPost(NULL, array(
      'commerce_payment[payment_method]' => 'commerce_payment_example|commerce_payment_commerce_payment_example',
    ), t('Continue to next step'));

    // Load required entities.
    $order = commerce_order_load($order->order_id);
    entity_get_controller('commerce_order')
      ->resetCache();
    $recurring_entities = commerce_recurring_load_by_order($order);
    $recurring_entity = reset($recurring_entities);
    $recurring_wrapper = entity_metadata_wrapper('commerce_recurring', $recurring_entity);
    $this
      ->assertTrue(!empty($recurring_entities), 'A recurring entity was created for the order');
    $this
      ->assertEqual(count($recurring_entities), 1, 'Only one recurring entity was created for the order');
    $this
      ->assertEqual($recurring_wrapper->commerce_recurring_ref_product
      ->value(), $recurring_product, 'Recurring product is associated with the recurring entity');
    $this
      ->assertEqual($recurring_entity->uid, $this->customer->uid, 'Recurring entity is assigned to the registered user');
  }

  /**
   * Test anonymous behaviour. Non-existing user
   */
  function testCommerceRecurringAnonymousOrder() {
    $recurring_product = $this
      ->createRecurringProduct();
    $this
      ->createDummyProductDisplayContentType('product_display', TRUE, 'field_product', FIELD_CARDINALITY_UNLIMITED);
    $node = $this
      ->createDummyProductNode(array(
      $recurring_product->product_id,
    ));
    user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
      'access checkout' => TRUE,
    ));

    // Ensure we're not logged in.
    $this
      ->drupalLogout();

    // Override user variable to get the enviroment fully set.
    global $user;
    $user = user_load(0);

    // Submit the add to cart form.
    $this
      ->drupalPost('node/' . $node->nid, array(), t('Add to cart'));

    // Get the order for the anonymous user.
    $orders = commerce_order_load_multiple(array(), array(
      'uid' => $user->uid,
      'status' => 'cart',
    ), TRUE);
    $order = reset($orders);

    // Reset the cache as we don't want to keep the lock.
    entity_get_controller('commerce_order')
      ->resetCache();
    $this
      ->drupalPost($this
      ->getCommerceUrl('cart'), array(), t('Checkout'));

    // Generate random information, as city, postal code, etc.
    $address_info = $this
      ->generateAddressInformation();

    // Fill in the billing address information.
    $billing_pane = $this
      ->xpath("//select[starts-with(@name, 'customer_profile_billing[commerce_customer_address]')]");
    $this
      ->drupalPostAJAX(NULL, array(
      (string) $billing_pane[0]['name'] => 'US',
    ), (string) $billing_pane[0]['name']);

    // Fill in the required information for billing pane, with a random State.
    $info = array(
      'account[login][mail]' => $this
        ->randomName() . '@example.com',
      'customer_profile_billing[commerce_customer_address][und][0][name_line]' => $address_info['name_line'],
      'customer_profile_billing[commerce_customer_address][und][0][thoroughfare]' => $address_info['thoroughfare'],
      'customer_profile_billing[commerce_customer_address][und][0][locality]' => $address_info['locality'],
      'customer_profile_billing[commerce_customer_address][und][0][administrative_area]' => 'KY',
      'customer_profile_billing[commerce_customer_address][und][0][postal_code]' => $address_info['postal_code'],
    );
    $this
      ->drupalPost(NULL, $info, t('Continue to next step'));

    // Finish checkout process
    $this
      ->drupalPost(NULL, array(
      'commerce_payment[payment_method]' => 'commerce_payment_example|commerce_payment_commerce_payment_example',
    ), t('Continue to next step'));

    // Load required entities.
    $order = commerce_order_load($order->order_id);
    entity_get_controller('commerce_order')
      ->resetCache();
    $recurring_entities = commerce_recurring_load_by_order($order);
    $recurring_entity = reset($recurring_entities);
    $recurring_wrapper = entity_metadata_wrapper('commerce_recurring', $recurring_entity);
    $this
      ->assertTrue(!empty($recurring_entities), 'A recurring entity was created for the order');
    $this
      ->assertEqual(count($recurring_entities), 1, 'Only one recurring entity was created for the order');
    $this
      ->assertEqual($recurring_wrapper->commerce_recurring_ref_product
      ->value(), $recurring_product, 'Recurring product is associated with the recurring entity');
    debug($recurring_entity);
    $this
      ->assertEqual($recurring_entity->uid, $order->uid, 'Recurring entity is assigned to the registered user');
  }

  /**
   * Test purchasing a Regular product and a recurring product.
   */
  function testCommerceRecurringRegularAndRecurringProducts() {
    $this
      ->drupalLogin($this->customer);
    $regular_product = $this
      ->createDummyProduct();
    $line_item = commerce_cart_product_add_by_id($regular_product->product_id, 1, TRUE, $this->customer->uid);
    $recurring_product = $this
      ->createRecurringProduct();
    $line_item = commerce_cart_product_add_by_id($recurring_product->product_id, 1, TRUE, $this->customer->uid);
    $this
      ->drupalPost($this
      ->getCommerceUrl('cart'), array(), t('Checkout'));

    // Generate random information, as city, postal code, etc.
    $address_info = $this
      ->generateAddressInformation();

    // Fill in the billing address information.
    $billing_pane = $this
      ->xpath("//select[starts-with(@name, 'customer_profile_billing[commerce_customer_address]')]");
    $this
      ->drupalPostAJAX(NULL, array(
      (string) $billing_pane[0]['name'] => 'US',
    ), (string) $billing_pane[0]['name']);

    // Fill in the required information for billing pane, with a random State.
    $info = array(
      'customer_profile_billing[commerce_customer_address][und][0][name_line]' => $address_info['name_line'],
      'customer_profile_billing[commerce_customer_address][und][0][thoroughfare]' => $address_info['thoroughfare'],
      'customer_profile_billing[commerce_customer_address][und][0][locality]' => $address_info['locality'],
      'customer_profile_billing[commerce_customer_address][und][0][administrative_area]' => 'KY',
      'customer_profile_billing[commerce_customer_address][und][0][postal_code]' => $address_info['postal_code'],
    );
    $this
      ->drupalPost(NULL, $info, t('Continue to next step'));

    // Finish checkout process
    $this
      ->drupalPost(NULL, array(
      'commerce_payment[payment_method]' => 'commerce_payment_example|commerce_payment_commerce_payment_example',
    ), t('Continue to next step'));

    // Load required entities.
    $order = commerce_order_load($line_item->order_id);
    $recurring_entities = commerce_recurring_load_by_order($order);
    $recurring_entity = reset($recurring_entities);
    $recurring_wrapper = entity_metadata_wrapper('commerce_recurring', $recurring_entity);
    $this
      ->assertTrue(!empty($recurring_entities), t('A recurring entity was created for the order'));
    $this
      ->assertEqual(count($recurring_entities), 1, t('Only one recurring entity was created for the order'));
    $this
      ->assertEqual($recurring_wrapper->commerce_recurring_ref_product
      ->value(), $recurring_product, t('Recurring product is associated with the recurring entity'));
    $this
      ->assertNotEqual($recurring_wrapper->commerce_recurring_ref_product
      ->value(), $regular_product, t('Regular product is not associated with the recurring entity'));
  }

  /**
   * Test purchasing a several recurring products.
   */
  function testCommerceRecurringPurchaseTwoRecurringProducts() {
    $this
      ->drupalLogin($this->customer);
    $first_recurring_product = $this
      ->createRecurringProduct();
    $line_item = commerce_cart_product_add_by_id($first_recurring_product->product_id, 1, TRUE, $this->customer->uid);
    $second_recurring_product = $this
      ->createRecurringProduct();
    $line_item = commerce_cart_product_add_by_id($second_recurring_product->product_id, 1, TRUE, $this->customer->uid);
    $this
      ->drupalPost($this
      ->getCommerceUrl('cart'), array(), t('Checkout'));

    // Generate random information, as city, postal code, etc.
    $address_info = $this
      ->generateAddressInformation();

    // Fill in the billing address information.
    $billing_pane = $this
      ->xpath("//select[starts-with(@name, 'customer_profile_billing[commerce_customer_address]')]");
    $this
      ->drupalPostAJAX(NULL, array(
      (string) $billing_pane[0]['name'] => 'US',
    ), (string) $billing_pane[0]['name']);

    // Fill in the required information for billing pane, with a random State.
    $info = array(
      'customer_profile_billing[commerce_customer_address][und][0][name_line]' => $address_info['name_line'],
      'customer_profile_billing[commerce_customer_address][und][0][thoroughfare]' => $address_info['thoroughfare'],
      'customer_profile_billing[commerce_customer_address][und][0][locality]' => $address_info['locality'],
      'customer_profile_billing[commerce_customer_address][und][0][administrative_area]' => 'KY',
      'customer_profile_billing[commerce_customer_address][und][0][postal_code]' => $address_info['postal_code'],
    );
    $this
      ->drupalPost(NULL, $info, t('Continue to next step'));

    // Finish checkout process
    $this
      ->drupalPost(NULL, array(
      'commerce_payment[payment_method]' => 'commerce_payment_example|commerce_payment_commerce_payment_example',
    ), t('Continue to next step'));
    $order = commerce_order_load($line_item->order_id);
    $this
      ->assertEqual(count(commerce_recurring_load_by_order($order)), 2, t('Two recurring entities are created when there are two recurring products in the cart.'));
  }

  /**
   * Test recurring entity creation with quantity.
   */
  function testCommerceRecurringCreatingRecurringEntityQuantity() {
    $this
      ->drupalLogin($this->customer);
    $product = $this
      ->createRecurringProduct();
    $line_item = commerce_cart_product_add_by_id($product->product_id, 2, TRUE, $this->customer->uid);
    $this
      ->drupalPost($this
      ->getCommerceUrl('cart'), array(), t('Checkout'));

    // Generate random information, as city, postal code, etc.
    $address_info = $this
      ->generateAddressInformation();

    // Fill in the billing address information.
    $billing_pane = $this
      ->xpath("//select[starts-with(@name, 'customer_profile_billing[commerce_customer_address]')]");
    $this
      ->drupalPostAJAX(NULL, array(
      (string) $billing_pane[0]['name'] => 'US',
    ), (string) $billing_pane[0]['name']);

    // Fill in the required information for billing pane, with a random State.
    $info = array(
      'customer_profile_billing[commerce_customer_address][und][0][name_line]' => $address_info['name_line'],
      'customer_profile_billing[commerce_customer_address][und][0][thoroughfare]' => $address_info['thoroughfare'],
      'customer_profile_billing[commerce_customer_address][und][0][locality]' => $address_info['locality'],
      'customer_profile_billing[commerce_customer_address][und][0][administrative_area]' => 'KY',
      'customer_profile_billing[commerce_customer_address][und][0][postal_code]' => $address_info['postal_code'],
    );
    $this
      ->drupalPost(NULL, $info, t('Continue to next step'));

    // Finish checkout process
    $this
      ->drupalPost(NULL, array(
      'commerce_payment[payment_method]' => 'commerce_payment_example|commerce_payment_commerce_payment_example',
    ), t('Continue to next step'));
    $order = commerce_order_load($line_item->order_id);
    $recurring_entities = commerce_recurring_load_by_order($order);
    $recurring_entity = reset($recurring_entities);
    $this
      ->assertEqual($recurring_entity->quantity, 2, t('The recurring entity generated has quantity 2.'));
    $this
      ->assertEqual($recurring_entity->commerce_recurring_fixed_price[LANGUAGE_NONE][0]['amount'], $product->commerce_recurring_ini_price[LANGUAGE_NONE][0]['amount'], t('Recurring entity fixed price is the product initial price.'));
    $this
      ->assertEqual(count(commerce_recurring_load_by_order($order)), 1, t('Just one recurring entity has been created.'));
  }

  /**
   * Test recurring orders with quantity.
   */
  function testCommerceRecurringCronOrderCreationWithQuantity() {

    // Create a recurring entity.
    $product = $this
      ->createRecurringProduct();
    $line_item = commerce_cart_product_add_by_id($product->product_id, 2, TRUE, $this->customer->uid);
    $recurring_entity = $this
      ->createRecurringEntity($product, 2);
    $initial_order = commerce_order_load($line_item->order_id);
    $initial_order->commerce_customer_billing = (array) $this
      ->createDummyCustomerProfile('billing', $this->customer->uid);
    $initial_order->status = 'completed';
    commerce_order_save($initial_order);
    commerce_cart_order_ids_reset();

    // Run cron.
    drupal_cron_run();

    // Check if the order has been correctly created and it's linked to the
    // recurring entity.
    $recurring_entities = entity_load('commerce_recurring', array(
      $recurring_entity->id,
    ), array(), TRUE);
    $recurring_entity = reset($recurring_entities);
    $recurring_wrapper = entity_metadata_wrapper('commerce_recurring', $recurring_entity);

    // The order is the second one now.
    $order_wrapper = $recurring_wrapper->commerce_recurring_order
      ->get(1);
    $order = $order_wrapper
      ->value();
    $this
      ->assertTrue(isset($order), t('New order has been created for the recurring entity'));
    $this
      ->assertEqual($order_wrapper->commerce_line_items
      ->get(0)->quantity
      ->value(), 2, t('Order line item with the recurring product has quantity 2.'));
  }

  /**
   * Test product is recurring check.
   */
  function testCommerceRecurringProductIsRecurring() {

    // Create a recurring and a non recurring product.
    $recurring_product = $this
      ->createRecurringProduct();
    $regular_product = $this
      ->createDummyProduct();
    $this
      ->assertFalse(commerce_recurring_product_is_recurring($regular_product), t('Regular product not identified as recurring.'));
    $this
      ->assertTrue(commerce_recurring_product_is_recurring($recurring_product), t('Recurring product identified as recurring.'));
  }

  /**
   * Test price list for recurring products.
   */
  function testCommerceRecurringProductPriceListing() {
    $this
      ->drupalLogin($this->customer);
    $recurring_product = $this
      ->createRecurringProduct();
    $this
      ->createDummyProductDisplayContentType('product_display', TRUE, 'field_product', FIELD_CARDINALITY_UNLIMITED);
    $node = $this
      ->createDummyProductNode(array(
      $recurring_product->product_id,
    ));
    $expected_price = commerce_currency_format($recurring_product->commerce_recurring_ini_price[LANGUAGE_NONE][0]['amount'], $recurring_product->commerce_recurring_ini_price[LANGUAGE_NONE][0]['currency_code']);

    // Check if the price is right in the product display page.
    // Price should be the initial one.
    $this
      ->drupalGet('node/' . $node->nid);

    // Add the cart block to the product page.
    $site_admin = $this
      ->createSiteAdmin();
    $this
      ->drupalLogin($site_admin);
    $this
      ->drupalGet('admin/structure/block/manage');
    $edit = array();
    $edit['blocks[commerce_cart_cart][region]'] = 'sidebar_first';
    $this
      ->drupalPost('admin/structure/block', $edit, t('Save blocks'));

    // Check if the price is right after adding the product to the cart.
    $this
      ->drupalLogin($this->customer);
    $this
      ->drupalPost('node/' . $node->nid, array(), t('Add to cart'));
    $this
      ->assertText($expected_price, t('Recurring product price in the display page (with cart) is the initial one as expected.'));
  }

  /**
   * Test if the recurring entity is disabled when cancelling an order.
   */
  function testCommerceRecurringCancelRecurringFromOrder() {

    // Create a recurring entity.
    $product = $this
      ->createRecurringProduct();
    $line_item = commerce_cart_product_add_by_id($product->product_id, 1, TRUE, $this->customer->uid);
    $start_date = new DateObject('2010-01-01');
    $due_date = new DateObject();
    $due_date
      ->sub(new DateInterval('P1D'));
    $recurring_entity = $this
      ->createRecurringEntity($product, 1, $start_date, $due_date);
    $order = commerce_order_load($line_item->order_id);
    $order->commerce_customer_billing = (array) $this
      ->createDummyCustomerProfile('billing', $this->customer->uid);
    $order->status = 'completed';
    commerce_order_save($order);
    $order->status = 'canceled';
    commerce_order_save($order);
    $recurring_entity = entity_load_single('commerce_recurring', $recurring_entity->id);
    $this
      ->assertEqual($recurring_entity->status, 0, t('Recurring entity has been disabled when the order is canceled'));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CommerceBaseTestCase::$profile protected property The profile to install as a basis for testing. Overrides DrupalWebTestCase::$profile
CommerceBaseTestCase::assertProductAddedToCart public function Asserts that a product has been added to the cart.
CommerceBaseTestCase::assertProductCreated public function Asserts that a product has been created.
CommerceBaseTestCase::attachProductReferenceField public function Attach a product reference field to a given content type. Creates the field if the given name doesn't already exist. Automatically sets the display formatters to be the "add to cart form" for the teaser and full modes.
CommerceBaseTestCase::createDummyCustomerProfile public function Create a customer profile.
CommerceBaseTestCase::createDummyOrder public function Create a dummy order in a given status.
CommerceBaseTestCase::createDummyProduct public function Creates a dummy product for use with other tests.
CommerceBaseTestCase::createDummyProductDisplayContentType public function Create a dummy product display content type.
CommerceBaseTestCase::createDummyProductNode public function Creates a product display node with an associated product.
CommerceBaseTestCase::createDummyProductNodeBatch public function Create a full product node without worrying about the earlier steps in the process.
CommerceBaseTestCase::createDummyProductType public function Creates a dummy product type for use with other tests.
CommerceBaseTestCase::createDummyTaxRate public function * Create a dummy tax rate. * *
CommerceBaseTestCase::createDummyTaxType public function * Create a dummy tax type. * *
CommerceBaseTestCase::createSiteAdmin protected function Returns a site administrator user. Only has permissions for administering modules in Drupal core.
CommerceBaseTestCase::createStoreAdmin protected function Returns a store administrator user. Only has permissions for administering Commerce modules.
CommerceBaseTestCase::createStoreCustomer protected function Returns a store customer. It's a regular user with some Commerce permissions as access to checkout.
CommerceBaseTestCase::createUserWithPermissionHelper protected function Wrapper to easily create users from arrays returned by permissionBuilder().
CommerceBaseTestCase::enableCurrencies public function Enable extra currencies in the store.
CommerceBaseTestCase::generateAddressInformation protected function Generate random valid information for Address information.
CommerceBaseTestCase::generateEmail protected function Generate a random valid email
CommerceBaseTestCase::getCommerceUrl protected function Return one of the Commerce configured urls.
CommerceBaseTestCase::modulesUp protected function Checks if a group of modules is enabled.
CommerceBaseTestCase::permissionBuilder protected function Helper function to get different combinations of permission sets.
CommerceBaseTestCase::setUpHelper protected function Helper function to determine which modules should be enabled. Should be used in place of standard parent::setUp('moduleA', 'moduleB') call. 1
CommerceRecurringTestCase::$customer private property User for the testing.
CommerceRecurringTestCase::createRecurringEntity public function Creates a recurring entity to be used in other tests.
CommerceRecurringTestCase::createRecurringProduct public function Creates a recurring product for use with other tests.
CommerceRecurringTestCase::getInfo public static function getInfo() returns properties that are displayed in the test selection form.
CommerceRecurringTestCase::setUp public function setUp() performs any pre-requisite tasks that need to happen. Overrides DrupalWebTestCase::setUp
CommerceRecurringTestCase::testCommerceRecurringAnonymousOrder function Test anonymous behaviour. Non-existing user
CommerceRecurringTestCase::testCommerceRecurringAnonymousOrderExistingUser function Test anonymous behaviour. Existing user
CommerceRecurringTestCase::testCommerceRecurringCancelRecurringFromOrder function Test if the recurring entity is disabled when cancelling an order.
CommerceRecurringTestCase::testCommerceRecurringCreatingRecurringEntityQuantity function Test recurring entity creation with quantity.
CommerceRecurringTestCase::testCommerceRecurringCronOrderCreation function Test cron run and order creation on recurring entity date base.
CommerceRecurringTestCase::testCommerceRecurringCronOrderCreationWithQuantity function Test recurring orders with quantity.
CommerceRecurringTestCase::testCommerceRecurringEndDate function Test recurring entity end date.
CommerceRecurringTestCase::testCommerceRecurringEntityCreation function Create a Recurring entity.
CommerceRecurringTestCase::testCommerceRecurringEntityCreationWorkflow function When creating an order and finish a payment, recurring entity
CommerceRecurringTestCase::testCommerceRecurringEntityCreationWorkflowNoInitialDate function Test workflow with no initial date.
CommerceRecurringTestCase::testCommerceRecurringProductIsRecurring function Test product is recurring check.
CommerceRecurringTestCase::testCommerceRecurringProductPriceListing function Test price list for recurring products.
CommerceRecurringTestCase::testCommerceRecurringPurchaseTwoRecurringProducts function Test purchasing a several recurring products.
CommerceRecurringTestCase::testCommerceRecurringRegularAndRecurringProducts function Test purchasing a Regular product and a recurring product.
CommerceRecurringTestCase::testCommerceRecurringUpdateRecurringEntity function Test recurring entity update when orders created in cron are processed.
CommerceRecurringTestCase::testCommmerceRecurringRegularProduct function Test adding a regular product so it shouldn't recur.
CommerceRecurringTestCase::testCreateRecurringProduct function Test creating a recurring product.
DrupalTestCase::$assertions protected property Assertions thrown in that test case.
DrupalTestCase::$databasePrefix protected property The database prefix of this test run.
DrupalTestCase::$originalFileDirectory protected property The original file directory, before it was changed for testing purposes.
DrupalTestCase::$results public property Current results of this test case.
DrupalTestCase::$setup protected property Flag to indicate whether the test has been set up.
DrupalTestCase::$setupDatabasePrefix protected property
DrupalTestCase::$setupEnvironment protected property
DrupalTestCase::$skipClasses protected property This class is skipped when looking for the source of an assertion.
DrupalTestCase::$testId protected property The test run ID.
DrupalTestCase::$timeLimit protected property Time limit for the test.
DrupalTestCase::$useSetupInstallationCache public property Whether to cache the installation part of the setUp() method.
DrupalTestCase::$useSetupModulesCache public property Whether to cache the modules installation part of the setUp() method.
DrupalTestCase::$verboseDirectoryUrl protected property URL to the verbose output file directory.
DrupalTestCase::assert protected function Internal helper: stores the assert.
DrupalTestCase::assertEqual protected function Check to see if two values are equal.
DrupalTestCase::assertFalse protected function Check to see if a value is false (an empty string, 0, NULL, or FALSE).
DrupalTestCase::assertIdentical protected function Check to see if two values are identical.
DrupalTestCase::assertNotEqual protected function Check to see if two values are not equal.
DrupalTestCase::assertNotIdentical protected function Check to see if two values are not identical.
DrupalTestCase::assertNotNull protected function Check to see if a value is not NULL.
DrupalTestCase::assertNull protected function Check to see if a value is NULL.
DrupalTestCase::assertTrue protected function Check to see if a value is not false (not an empty string, 0, NULL, or FALSE).
DrupalTestCase::deleteAssert public static function Delete an assertion record by message ID.
DrupalTestCase::error protected function Fire an error assertion. 1
DrupalTestCase::errorHandler public function Handle errors during test runs. 1
DrupalTestCase::exceptionHandler protected function Handle exceptions.
DrupalTestCase::fail protected function Fire an assertion that is always negative.
DrupalTestCase::generatePermutations public static function Converts a list of possible parameters into a stack of permutations.
DrupalTestCase::getAssertionCall protected function Cycles through backtrace until the first non-assertion method is found.
DrupalTestCase::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
DrupalTestCase::insertAssert public static function Store an assertion from outside the testing context.
DrupalTestCase::pass protected function Fire an assertion that is always positive.
DrupalTestCase::randomName public static function Generates a random string containing letters and numbers.
DrupalTestCase::randomString public static function Generates a random string of ASCII characters of codes 32 to 126.
DrupalTestCase::run public function Run all tests in this class.
DrupalTestCase::verbose protected function Logs a verbose message in a text file.
DrupalWebTestCase::$additionalCurlOptions protected property Additional cURL options.
DrupalWebTestCase::$content protected property The content of the page currently loaded in the internal browser.
DrupalWebTestCase::$cookieFile protected property The current cookie file used by cURL.
DrupalWebTestCase::$cookies protected property The cookies of the page currently loaded in the internal browser.
DrupalWebTestCase::$curlHandle protected property The handle of the current cURL connection.
DrupalWebTestCase::$drupalSettings protected property The value of the Drupal.settings JavaScript variable for the page currently loaded in the internal browser.
DrupalWebTestCase::$elements protected property The parsed version of the page.
DrupalWebTestCase::$generatedTestFiles protected property Whether the files were copied to the test files directory.
DrupalWebTestCase::$headers protected property The headers of the page currently loaded in the internal browser.
DrupalWebTestCase::$httpauth_credentials protected property HTTP authentication credentials (<username>:<password>).
DrupalWebTestCase::$httpauth_method protected property HTTP authentication method
DrupalWebTestCase::$loggedInUser protected property The current user logged in using the internal browser.
DrupalWebTestCase::$originalShutdownCallbacks protected property The original shutdown handlers array, before it was cleaned for testing purposes.
DrupalWebTestCase::$originalUser protected property The original user, before it was changed to a clean uid = 1 for testing purposes.
DrupalWebTestCase::$plainTextContent protected property The content of the page currently loaded in the internal browser (plain text version).
DrupalWebTestCase::$redirect_count protected property The number of redirects followed during the handling of a request.
DrupalWebTestCase::$session_id protected property The current session ID, if available.
DrupalWebTestCase::$session_name protected property The current session name, if available.
DrupalWebTestCase::$url protected property The URL currently loaded in the internal browser.
DrupalWebTestCase::assertField protected function Asserts that a field exists with the given name or ID.
DrupalWebTestCase::assertFieldById protected function Asserts that a field exists in the current page with the given ID and value.
DrupalWebTestCase::assertFieldByName protected function Asserts that a field exists in the current page with the given name and value.
DrupalWebTestCase::assertFieldByXPath protected function Asserts that a field exists in the current page by the given XPath.
DrupalWebTestCase::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
DrupalWebTestCase::assertLink protected function Pass if a link with the specified label is found, and optional with the specified index.
DrupalWebTestCase::assertLinkByHref protected function Pass if a link containing a given href (part) is found.
DrupalWebTestCase::assertMail protected function Asserts that the most recently sent e-mail message has the given value.
DrupalWebTestCase::assertMailPattern protected function Asserts that the most recently sent e-mail message has the pattern in it.
DrupalWebTestCase::assertMailString protected function Asserts that the most recently sent e-mail message has the string in it.
DrupalWebTestCase::assertNoDuplicateIds protected function Asserts that each HTML ID is used for just a single element.
DrupalWebTestCase::assertNoField protected function Asserts that a field does not exist with the given name or ID.
DrupalWebTestCase::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
DrupalWebTestCase::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
DrupalWebTestCase::assertNoFieldByXPath protected function Asserts that a field doesn't exist or its value doesn't match, by XPath.
DrupalWebTestCase::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
DrupalWebTestCase::assertNoLink protected function Pass if a link with the specified label is not found.
DrupalWebTestCase::assertNoLinkByHref protected function Pass if a link containing a given href (part) is not found.
DrupalWebTestCase::assertNoOptionSelected protected function Asserts that a select option in the current page is not checked.
DrupalWebTestCase::assertNoPattern protected function Will trigger a pass if the perl regex pattern is not present in raw content.
DrupalWebTestCase::assertNoRaw protected function Pass if the raw text is NOT found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertNoResponse protected function Asserts the page did not return the specified response code.
DrupalWebTestCase::assertNoText protected function Pass if the text is NOT found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertNoTitle protected function Pass if the page title is not the given string.
DrupalWebTestCase::assertNoUniqueText protected function Pass if the text is found MORE THAN ONCE on the text version of the page.
DrupalWebTestCase::assertOptionSelected protected function Asserts that a select option in the current page is checked.
DrupalWebTestCase::assertPattern protected function Will trigger a pass if the Perl regex pattern is found in the raw content.
DrupalWebTestCase::assertRaw protected function Pass if the raw text IS found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertResponse protected function Asserts the page responds with the specified response code.
DrupalWebTestCase::assertText protected function Pass if the text IS found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertTextHelper protected function Helper for assertText and assertNoText.
DrupalWebTestCase::assertThemeOutput protected function Asserts themed output.
DrupalWebTestCase::assertTitle protected function Pass if the page title is the given string.
DrupalWebTestCase::assertUniqueText protected function Pass if the text is found ONLY ONCE on the text version of the page.
DrupalWebTestCase::assertUniqueTextHelper protected function Helper for assertUniqueText and assertNoUniqueText.
DrupalWebTestCase::assertUrl protected function Pass if the internal browser's URL matches the given path.
DrupalWebTestCase::buildXPathQuery protected function Builds an XPath query.
DrupalWebTestCase::changeDatabasePrefix protected function Changes the database connection to the prefixed one.
DrupalWebTestCase::checkForMetaRefresh protected function Check for meta refresh tag and if found call drupalGet() recursively. This function looks for the http-equiv attribute to be set to "Refresh" and is case-sensitive.
DrupalWebTestCase::checkPermissions protected function Check to make sure that the array of permissions are valid.
DrupalWebTestCase::clickLink protected function Follows a link by name.
DrupalWebTestCase::constructFieldXpath protected function Helper function: construct an XPath for the given set of attributes and value.
DrupalWebTestCase::copySetupCache protected function Copy the setup cache from/to another table and files directory.
DrupalWebTestCase::cronRun protected function Runs cron in the Drupal installed by Simpletest.
DrupalWebTestCase::curlClose protected function Close the cURL handler and unset the handler.
DrupalWebTestCase::curlExec protected function Initializes and executes a cURL request.
DrupalWebTestCase::curlHeaderCallback protected function Reads headers and registers errors received from the tested site.
DrupalWebTestCase::curlInitialize protected function Initializes the cURL connection.
DrupalWebTestCase::drupalCompareFiles protected function Compare two files based on size and file name.
DrupalWebTestCase::drupalCreateContentType protected function Creates a custom content type based on default settings.
DrupalWebTestCase::drupalCreateNode protected function Creates a node based on default settings.
DrupalWebTestCase::drupalCreateRole protected function Creates a role with specified permissions.
DrupalWebTestCase::drupalCreateUser protected function Create a user with a given set of permissions.
DrupalWebTestCase::drupalGet protected function Retrieves a Drupal path or an absolute path.
DrupalWebTestCase::drupalGetAJAX protected function Retrieve a Drupal path or an absolute path and JSON decode the result.
DrupalWebTestCase::drupalGetContent protected function Gets the current raw HTML of requested page.
DrupalWebTestCase::drupalGetHeader protected function Gets the value of an HTTP response header. If multiple requests were required to retrieve the page, only the headers from the last request will be checked by default. However, if TRUE is passed as the second argument, all requests will be processed…
DrupalWebTestCase::drupalGetHeaders protected function Gets the HTTP response headers of the requested page. Normally we are only interested in the headers returned by the last request. However, if a page is redirected or HTTP authentication is in use, multiple requests will be required to retrieve the…
DrupalWebTestCase::drupalGetMails protected function Gets an array containing all e-mails sent during this test case.
DrupalWebTestCase::drupalGetNodeByTitle function Get a node from the database based on its title.
DrupalWebTestCase::drupalGetSettings protected function Gets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::drupalGetTestFiles protected function Get a list files that can be used in tests.
DrupalWebTestCase::drupalGetToken protected function Generate a token for the currently logged in user.
DrupalWebTestCase::drupalHead protected function Retrieves only the headers for a Drupal path or an absolute path.
DrupalWebTestCase::drupalLogin protected function Log in a user with the internal browser.
DrupalWebTestCase::drupalLogout protected function
DrupalWebTestCase::drupalPost protected function Execute a POST request on a Drupal page. It will be done as usual POST request with SimpleBrowser.
DrupalWebTestCase::drupalPostAJAX protected function Execute an Ajax submission.
DrupalWebTestCase::drupalSetContent protected function Sets the raw HTML content. This can be useful when a page has been fetched outside of the internal browser and assertions need to be made on the returned page.
DrupalWebTestCase::drupalSetSettings protected function Sets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::getAbsoluteUrl protected function Takes a path and returns an absolute path.
DrupalWebTestCase::getAllOptions protected function Get all option elements, including nested options, in a select.
DrupalWebTestCase::getSelectedItem protected function Get the selected value from a select field.
DrupalWebTestCase::getSetupCacheKey protected function Returns the cache key used for the setup caching.
DrupalWebTestCase::getUrl protected function Get the current URL from the cURL handler.
DrupalWebTestCase::handleForm protected function Handle form input related to drupalPost(). Ensure that the specified fields exist and attempt to create POST data in the correct manner for the particular field type.
DrupalWebTestCase::loadSetupCache protected function Copies the cached tables and files for a cached installation setup.
DrupalWebTestCase::parse protected function Parse content returned from curlExec using DOM and SimpleXML.
DrupalWebTestCase::preloadRegistry protected function Preload the registry from the testing site.
DrupalWebTestCase::prepareDatabasePrefix protected function Generates a database prefix for running tests.
DrupalWebTestCase::prepareEnvironment protected function Prepares the current environment for running the test.
DrupalWebTestCase::recursiveDirectoryCopy protected function Recursively copy one directory to another.
DrupalWebTestCase::refreshVariables protected function Refresh the in-memory set of variables. Useful after a page request is made that changes a variable in a different thread. 1
DrupalWebTestCase::resetAll protected function Reset all data structures after having enabled new modules.
DrupalWebTestCase::storeSetupCache protected function Store the installation setup to a cache.
DrupalWebTestCase::tearDown protected function Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix. 6
DrupalWebTestCase::verboseEmail protected function Outputs to verbose the most recent $count emails sent.
DrupalWebTestCase::xpath protected function Perform an xpath search on the contents of the internal browser. The search is relative to the root element (HTML tag normally) of the page.
DrupalWebTestCase::__construct function Constructor for DrupalWebTestCase. Overrides DrupalTestCase::__construct 1