You are here

protected function UbercartTestBase::checkout in Ubercart 8.4

Executes the checkout process.

Return value

\Drupal\uc_order\Entity\Order|false The created order, or FALSE if the order could not be created.

File

uc_store/src/Tests/UbercartTestBase.php, line 292

Class

UbercartTestBase
Base class for Ubercart Simpletest tests.

Namespace

Drupal\uc_store\Tests

Code

protected function checkout(array $edit = []) {
  $this
    ->drupalPostForm('cart', [], 'Checkout');
  $this
    ->assertText(t('Enter your billing address and information here.'), 'Viewed cart page: Billing pane has been displayed.');
  $edit = $this
    ->populateCheckoutForm($edit);

  // Submit the checkout page.
  $this
    ->drupalPostForm('cart/checkout', $edit, t('Review order'));
  $this
    ->assertRaw(t('Your order is almost complete.'));

  // Complete the review page.
  $this
    ->drupalPostForm(NULL, [], t('Submit order'));
  $order_ids = \Drupal::entityQuery('uc_order')
    ->condition('billing_first_name', $edit['panes[billing][first_name]'])
    ->execute();
  $order_id = reset($order_ids);
  if ($order_id) {
    $this
      ->pass(SafeMarkup::format('Order %order_id has been created', [
      '%order_id' => $order_id,
    ]));
    $order = Order::load($order_id);
  }
  else {
    $this
      ->fail('No order was created.');
    $order = FALSE;
  }
  return $order;
}