You are here

protected function UbercartJavascriptTestBase::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/tests/src/FunctionalJavascript/UbercartJavascriptTestBase.php, line 172

Class

UbercartJavascriptTestBase
Base class for Ubercart PHPUnit browser tests.

Namespace

Drupal\Tests\uc_store\FunctionalJavascript

Code

protected function checkout(array $edit = []) {

  /** @var \Drupal\Tests\WebAssert $assert */
  $assert = $this
    ->assertSession();
  $this
    ->drupalGet('cart');
  $this
    ->submitForm([], 'Checkout');
  $assert
    ->pageTextContains('Enter your billing address and information here.', 'Viewed cart page: Billing pane has been displayed.');
  $edit = $this
    ->populateCheckoutForm($edit);

  // Submit the checkout page.
  $this
    ->drupalGet('cart/checkout');
  $this
    ->submitForm($edit, 'Review order');
  $assert
    ->pageTextContains('Your order is almost complete.');

  // Complete the review page.
  $this
    ->submitForm([], '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
      ->assertTrue(TRUE, format_string('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;
}