You are here

protected function UbercartOrderTestCase::ucCreateOrder in Ubercart 7.3

Same name and namespace in other branches
  1. 6.2 uc_order/uc_order.test \UbercartOrderTestCase::ucCreateOrder()

Helper function for creating an order programmatically.

1 call to UbercartOrderTestCase::ucCreateOrder()
UbercartOrderTestCase::testOrderEditing in uc_order/tests/uc_order.test
Tests admin editing of orders.

File

uc_order/tests/uc_order.test, line 153
Tests for Ubercart orders.

Class

UbercartOrderTestCase
Tests for Ubercart orders.

Code

protected function ucCreateOrder($customer) {
  $order = uc_order_new($customer->uid);
  uc_order_comment_save($order->order_id, 0, t('Order created programmatically.'), 'admin');
  $order_exists = db_query("SELECT 1 FROM {uc_orders} WHERE order_id = :order_id", array(
    ':order_id' => $order->order_id,
  ))
    ->fetchField();
  $this
    ->assertTrue($order_exists, t('Found order ID @order_id', array(
    '@order_id' => $order->order_id,
  )));
  $countries = uc_country_option_list();
  $country = array_rand($countries);
  $zones = uc_zone_option_list();
  $order->delivery_first_name = $this
    ->randomName(12);
  $order->delivery_last_name = $this
    ->randomName(12);
  $order->delivery_street1 = $this
    ->randomName(12);
  $order->delivery_street2 = $this
    ->randomName(12);
  $order->delivery_city = $this
    ->randomName(12);
  $order->delivery_zone = array_rand($zones[$countries[$country]]);
  $order->delivery_postal_code = mt_rand(10000, 99999);
  $order->delivery_country = $country;
  $order->billing_first_name = $this
    ->randomName(12);
  $order->billing_last_name = $this
    ->randomName(12);
  $order->billing_street1 = $this
    ->randomName(12);
  $order->billing_street2 = $this
    ->randomName(12);
  $order->billing_city = $this
    ->randomName(12);
  $order->billing_zone = array_rand($zones[$countries[$country]]);
  $order->billing_postal_code = mt_rand(10000, 99999);
  $order->billing_country = $country;
  uc_order_save($order);
  $db_order = db_query("SELECT * FROM {uc_orders} WHERE order_id = :order_id", array(
    ':order_id' => $order->order_id,
  ))
    ->fetchObject();
  $this
    ->assertEqual($order->delivery_first_name, $db_order->delivery_first_name);
  $this
    ->assertEqual($order->delivery_last_name, $db_order->delivery_last_name);
  $this
    ->assertEqual($order->delivery_street1, $db_order->delivery_street1);
  $this
    ->assertEqual($order->delivery_street2, $db_order->delivery_street2);
  $this
    ->assertEqual($order->delivery_city, $db_order->delivery_city);
  $this
    ->assertEqual($order->delivery_zone, $db_order->delivery_zone);
  $this
    ->assertEqual($order->delivery_postal_code, $db_order->delivery_postal_code);
  $this
    ->assertEqual($order->delivery_country, $db_order->delivery_country);
  $this
    ->assertEqual($order->billing_first_name, $db_order->billing_first_name);
  $this
    ->assertEqual($order->billing_last_name, $db_order->billing_last_name);
  $this
    ->assertEqual($order->billing_street1, $db_order->billing_street1);
  $this
    ->assertEqual($order->billing_street2, $db_order->billing_street2);
  $this
    ->assertEqual($order->billing_city, $db_order->billing_city);
  $this
    ->assertEqual($order->billing_zone, $db_order->billing_zone);
  $this
    ->assertEqual($order->billing_postal_code, $db_order->billing_postal_code);
  $this
    ->assertEqual($order->billing_country, $db_order->billing_country);
  return $order;
}