public function CheckoutOrderTest::testRegistrationAfterGuestOrderCheckout in Commerce Core 8.2
Tests that you can register after completing guest checkout.
File
- modules/
checkout/ tests/ src/ Functional/ CheckoutOrderTest.php, line 455
Class
- CheckoutOrderTest
- Tests the checkout of an order.
Namespace
Drupal\Tests\commerce_checkout\FunctionalCode
public function testRegistrationAfterGuestOrderCheckout() {
$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]' => 'User name',
'completion_register[pass][pass1]' => 'pass',
'completion_register[pass][pass2]' => 'pass',
], 'Create account');
$this
->assertSession()
->pageTextContains('Registration successful. You are now logged in.');
// Log out and try to login again with the chosen password.
$this
->drupalLogout();
$accounts = \Drupal::service('entity_type.manager')
->getStorage('user')
->loadByProperties([
'mail' => 'guest@example.com',
]);
/** @var \Drupal\user\UserInterface $account */
$account = reset($accounts);
$this
->assertTrue($account
->isActive());
$account->passRaw = 'pass';
$this
->drupalLogin($account);
// Checkout again as guest to test account validation.
$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');
$this
->assertCheckoutProgressStep('Login');
$this
->submitForm([], 'Continue as Guest');
$this
->assertCheckoutProgressStep('Order information');
$this
->submitForm([
'contact_information[email]' => 'guest2@example.com',
'contact_information[email_confirm]' => 'guest2@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 2. You can view your order on your account page when logged in.');
$this
->submitForm([
'completion_register[name]' => '',
'completion_register[pass][pass1]' => 'pass',
'completion_register[pass][pass2]' => 'pass',
], 'Create account');
$this
->assertSession()
->pageTextContains('You must enter a username.');
$this
->submitForm([
'completion_register[name]' => 'User name',
'completion_register[pass][pass1]' => '',
'completion_register[pass][pass2]' => '',
], 'Create account');
$this
->assertSession()
->pageTextContains('Password field is required.');
$this
->submitForm([
'completion_register[name]' => 'User @#.``^ ù % name invalid',
'completion_register[pass][pass1]' => 'pass',
'completion_register[pass][pass2]' => 'pass',
], 'Create account');
$this
->assertSession()
->pageTextContains('The username contains an illegal character.');
$this
->submitForm([
'completion_register[name]' => 'User name',
'completion_register[pass][pass1]' => 'pass',
'completion_register[pass][pass2]' => 'pass',
], 'Create account');
$this
->assertSession()
->pageTextContains('The username User name is already taken.');
}