You are here

public function CheckoutOrderTest::testRedirectAfterRegistrationOnCheckout in Commerce Core 8.2

Tests redirection after registering at the end of checkout.

File

modules/checkout/tests/src/Functional/CheckoutOrderTest.php, line 640

Class

CheckoutOrderTest
Tests the checkout of an order.

Namespace

Drupal\Tests\commerce_checkout\Functional

Code

public function testRedirectAfterRegistrationOnCheckout() {
  $this
    ->drupalLogout();
  $this
    ->drupalGet($this->product
    ->toUrl());
  $this
    ->submitForm([], 'Add to cart');
  $cart_link = $this
    ->getSession()
    ->getPage()
    ->findLink('your cart');
  $cart_link
    ->click();
  $this
    ->submitForm([], 'Checkout');

  // Checkout as guest.
  $this
    ->assertCheckoutProgressStep('Login');
  $this
    ->submitForm([], 'Continue as Guest');
  $this
    ->assertCheckoutProgressStep('Order information');
  $this
    ->submitForm([
    'contact_information[email]' => 'guest@example.com',
    'contact_information[email_confirm]' => 'guest@example.com',
    'billing_information[profile][address][0][address][given_name]' => $this
      ->randomString(),
    'billing_information[profile][address][0][address][family_name]' => $this
      ->randomString(),
    'billing_information[profile][address][0][address][organization]' => $this
      ->randomString(),
    'billing_information[profile][address][0][address][address_line1]' => $this
      ->randomString(),
    'billing_information[profile][address][0][address][postal_code]' => '94043',
    'billing_information[profile][address][0][address][locality]' => 'Mountain View',
    'billing_information[profile][address][0][address][administrative_area]' => 'CA',
  ], 'Continue to review');
  $this
    ->assertCheckoutProgressStep('Review');
  $this
    ->assertSession()
    ->pageTextContains('Contact information');
  $this
    ->assertSession()
    ->pageTextContains('Billing information');
  $this
    ->assertSession()
    ->pageTextContains('Order Summary');
  $this
    ->submitForm([], 'Complete checkout');
  $this
    ->assertSession()
    ->pageTextContains('Your order number is 1. You can view your order on your account page when logged in.');
  $this
    ->assertSession()
    ->pageTextContains('Create your account');
  $this
    ->submitForm([
    'completion_register[name]' => 'bob_redirect',
    'completion_register[pass][pass1]' => 'pass',
    'completion_register[pass][pass2]' => 'pass',
  ], 'Create account');
  $this
    ->assertSession()
    ->pageTextContains('Registration successful. You are now logged in.');

  // Confirm that a redirect had taken place.
  $url = Url::fromRoute('entity.user.edit_form', [
    'user' => 3,
  ], [
    'absolute' => TRUE,
  ]);
  $this
    ->assertSession()
    ->addressEquals($url
    ->toString());
}