You are here

function CommerceRecurringTestCase::testCommerceRecurringEndDate in Commerce Recurring Framework 7.2

Test recurring entity end date.

File

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

Class

CommerceRecurringTestCase
@file Unit tests for the commerce recurring module.

Code

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.'));
}