You are here

public function CommerceRecurringTestCase::createRecurringProduct in Commerce Recurring Framework 7.2

Creates a recurring product for use with other tests.

Return value

A product with most of it's basic fields set random values. FALSE if the appropiate modules were not available.

15 calls to CommerceRecurringTestCase::createRecurringProduct()
CommerceRecurringTestCase::createRecurringEntity in tests/commerce_recurring.test
Creates a recurring entity to be used in other tests.
CommerceRecurringTestCase::testCommerceRecurringAnonymousOrder in tests/commerce_recurring.test
Test anonymous behaviour. Non-existing user
CommerceRecurringTestCase::testCommerceRecurringAnonymousOrderExistingUser in tests/commerce_recurring.test
Test anonymous behaviour. Existing user
CommerceRecurringTestCase::testCommerceRecurringCancelRecurringFromOrder in tests/commerce_recurring.test
Test if the recurring entity is disabled when cancelling an order.
CommerceRecurringTestCase::testCommerceRecurringCreatingRecurringEntityQuantity in tests/commerce_recurring.test
Test recurring entity creation with quantity.

... See full list

File

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

Class

CommerceRecurringTestCase
@file Unit tests for the commerce recurring module.

Code

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