You are here

public function CommerceRecurringTestCase::createRecurringEntity in Commerce Recurring Framework 7.2

Creates a recurring entity to be used in other tests.

Parameters

entity $product: Commerce Product assigned to the Recurring entity.

int $quantity: Quantity of the product.

int $start_date: Initial date for recurring.

int $due_date: Due date for recurring.

int $end_date: End date for recurring.

Return value

bool A recurring entity with fields configured randomly unless they're

5 calls to CommerceRecurringTestCase::createRecurringEntity()
CommerceRecurringTestCase::testCommerceRecurringCancelRecurringFromOrder in tests/commerce_recurring.test
Test if the recurring entity is disabled when cancelling an order.
CommerceRecurringTestCase::testCommerceRecurringCronOrderCreation in tests/commerce_recurring.test
Test cron run and order creation on recurring entity date base.
CommerceRecurringTestCase::testCommerceRecurringCronOrderCreationWithQuantity in tests/commerce_recurring.test
Test recurring orders with quantity.
CommerceRecurringTestCase::testCommerceRecurringEndDate in tests/commerce_recurring.test
Test recurring entity end date.
CommerceRecurringTestCase::testCommerceRecurringUpdateRecurringEntity in tests/commerce_recurring.test
Test recurring entity update when orders created in cron are processed.

File

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

Class

CommerceRecurringTestCase
@file Unit tests for the commerce recurring module.

Code

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;
}