You are here

function UcCouponTestCase::checkout in Ubercart Discount Coupons 7.3

Executes the checkout process.

Overrides UbercartTestHelper::checkout

2 calls to UcCouponTestCase::checkout()
UcCouponTestCase::testCoupon in tests/uc_coupon.test
UcCouponTestCase::testGiftCertificate in tests/uc_coupon.test

File

tests/uc_coupon.test, line 70
Ubercart Discount Coupon Tests.

Class

UcCouponTestCase
SimpleTests for Ubercart Discount Coupons

Code

function checkout($coupons = array(), $total = FALSE) {
  $total = uc_currency_format($total);
  $this
    ->drupalPost('cart', array(
    'items[0][qty]' => 1,
  ), t('Checkout'));
  foreach ($coupons as $coupon) {
    $this
      ->assertRaw('Coupon ' . $coupon->code, "Coupon {$coupon->code} appears on checkout page.");
  }
  if ($total !== FALSE) {
    $this
      ->assertRaw($total, "The order total of {$total} is correct on the checkout page");
  }
  $edit = $this
    ->populateCheckoutForm();
  $this
    ->drupalPost(NULL, $edit, t('Review order'));
  foreach ($coupons as $coupon) {
    $this
      ->assertRaw('Coupon ' . $coupon->code, "Coupon {$coupon->code} appears on review page.");
  }
  if ($total !== FALSE) {
    $this
      ->assertRaw($total, "The order total of {$total} is correct on the review page");
  }

  // Complete the review page.
  $this
    ->drupalPost(NULL, array(), t('Submit order'));
  $order_id = db_query("SELECT order_id FROM {uc_orders} WHERE delivery_first_name = :name", array(
    ':name' => $edit['panes[delivery][delivery_first_name]'],
  ))
    ->fetchField();
  if ($order_id) {
    $order = uc_order_load($order_id);
    if ($total !== FALSE) {
      $this
        ->assertEqual(uc_currency_format(uc_order_get_total($order)), $total, 'Saved order total is correct');
    }
  }
  else {
    $this
      ->fail(t('No order was created.'));
    $order = FALSE;
  }
  return $order;
}