You are here

public function CommerceBaseTestCase::createDummyOrder in Commerce Core 7

Create a dummy order in a given status.

Parameters

$uid: ID of the user that owns the order.

$products: Array of products that are going to be added to the order: keys are product ids, values are the quantity of products to add.

$status: Status of the order

Return value

A commerce order object in the given status.

23 calls to CommerceBaseTestCase::createDummyOrder()
CommerceBaseTesterTestCase::testTestCreateDummyOrder in tests/commerce_base.test
Test the createDummyOrder function.
CommerceCheckoutTestProcess::testCommerceCheckoutAccessOrder in modules/checkout/tests/commerce_checkout.test
Test order completion page access.
CommerceCheckoutTestProcess::testCommerceCheckoutAccessPages in modules/checkout/tests/commerce_checkout.test
Test order completion page access.
CommerceCheckoutTestProcess::testCommerceCheckoutProcessAuthenticatedUser in modules/checkout/tests/commerce_checkout.test
Test the checkout process using an authenticated user.
CommerceCheckoutTestProcess::testCommerceCheckoutProgrammaticCheckout in modules/checkout/tests/commerce_checkout.test
Test programmatic checkout completion.

... See full list

File

tests/commerce_base.test, line 355
Defines abstract base test class for the Commerce module tests.

Class

CommerceBaseTestCase
Abstract class for Commerce testing. All Commerce tests should extend this class.

Code

public function createDummyOrder($uid = 1, $products = array(), $status = 'cart', $customer_profile_id = NULL) {

  // If there aren't any products to add to the order, create one.
  if (empty($products)) {
    $product = $this
      ->createDummyProduct('PROD-01', 'Product One', -1, 'USD', $uid);
    $products[$product->product_id] = rand(1, 10);
  }

  // Create a new shopping cart order by adding the products to it.
  foreach ($products as $product_id => $quantity) {
    if ($product = commerce_product_load($product_id)) {
      $line_item = commerce_product_line_item_new($product, $quantity);
      $line_item = commerce_cart_product_add($uid, $line_item);
    }
  }

  // Load the order for returning it.
  $order = commerce_cart_order_load($uid);
  if (!empty($customer_profile_id)) {
    $order->commerce_customer_billing[LANGUAGE_NONE][0]['profile_id'] = $customer_profile_id;
  }

  // If the order should be in a different status, update it.
  if ($status != 'cart') {
    $order = commerce_order_status_update($order, $status, TRUE);
  }
  commerce_order_save($order);
  return $order;
}