You are here

protected function CommerceReportsBaseTestCase::createOrders in Commerce Reporting 7.3

Helper function creating multiple dummy orders. If no customers or products exist, then one of each get created.

13 calls to CommerceReportsBaseTestCase::createOrders()
CommerceReportsCustomerTestCase::testMultipleCustomers in tests/commerce_reports.test
Make one customer perform multiple orders with multiple products. Then verifies if the reporting is correct.
CommerceReportsCustomerTestCase::testSingleCustomer in tests/commerce_reports.test
Tests creating a single order for a single customer, containing a single product with a variable quantity. Then verifies if the reporting is correct.
CommerceReportsCustomerTestCase::testSingleCustomerMultipleProducts in tests/commerce_reports.test
Make one customer perform multiple orders with multiple products. Then verifies if the reporting is correct.
CommerceReportsPaymentMethodTestCase::testExampleMethod in tests/commerce_reports.test
CommerceReportsProductTestCase::testMultipleOrdersProducts in tests/commerce_reports.test
Tests creating a multiple orders, containing multiple products with a variable quantity. Then verifies if the reporting is correct.

... See full list

File

tests/commerce_reports.test, line 46
Unit tests for the commerce reports module.

Class

CommerceReportsBaseTestCase
@file Unit tests for the commerce reports module.

Code

protected function createOrders($amount = 1, $createTransactions = FALSE, $possibleDates = array()) {
  if (empty($this->products)) {
    $this
      ->createProducts();
  }
  if (empty($this->customers)) {
    $this
      ->createCustomers();
  }
  $order_status = 'completed';
  if ($createTransactions) {
    $order_status = 'pending';
  }
  for ($i = 0; $i < $amount; $i++) {
    $totalProducts = rand(1, count($this->products));
    $products = array();
    for ($x = 0; $x < $totalProducts; $x++) {
      $product = $this->products[array_rand($this->products)];
      $products[$product->product_id] = rand(1, 10);
    }
    if (!($customer = next($this->customers))) {
      $customer = reset($this->customers);
    }
    $order = $this
      ->createDummyOrder($customer->uid, $products, $order_status);
    if (!empty($possibleDates)) {
      $date = $possibleDates[array_rand($possibleDates)];
      $order->created = $date;
      commerce_order_save($order);
    }
    $transaction = NULL;
    if ($createTransactions) {
      $transaction = commerce_payment_transaction_new('commerce_payment_example', $order->order_id);
      $transaction->amount = $order->commerce_order_total['und'][0]['amount'];
      $transaction->status = 'success';
      commerce_payment_transaction_save($transaction);
    }
    $this->orders[] = array(
      'commerce_transaction' => $transaction,
      'commerce_order' => $order,
      'products' => $products,
    );
  }
}