You are here

public function CheckoutOrderTest::testRegisterOrderCheckout in Commerce Core 8.2

Tests that you can register from the login checkout pane.

File

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

Class

CheckoutOrderTest
Tests the checkout of an order.

Namespace

Drupal\Tests\commerce_checkout\Functional

Code

public function testRegisterOrderCheckout() {
  $config = \Drupal::configFactory()
    ->getEditable('commerce_checkout.commerce_checkout_flow.default');
  $config
    ->set('configuration.panes.login.allow_guest_checkout', FALSE);
  $config
    ->set('configuration.panes.login.allow_registration', TRUE);
  $config
    ->save();
  $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
    ->assertSession()
    ->pageTextContains('New Customer');
  $this
    ->submitForm([
    'login[register][name]' => 'User name',
    'login[register][mail]' => 'guest@example.com',
    'login[register][password][pass1]' => 'pass',
    'login[register][password][pass2]' => 'pass',
  ], 'Create account and continue');
  $this
    ->assertSession()
    ->pageTextContains('Billing information');

  // Check breadcrumbs are not links. (the default setting)
  $this
    ->assertSession()
    ->elementNotExists('css', '.block-commerce-checkout-progress li.checkout-progress--step > a');

  // 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
    ->assertSession()
    ->pageTextContains('New Customer');
  $this
    ->submitForm([
    'login[register][name]' => 'User name',
    'login[register][mail]' => '',
    'login[register][password][pass1]' => 'pass',
    'login[register][password][pass2]' => 'pass',
  ], 'Create account and continue');
  $this
    ->assertSession()
    ->pageTextContains('Email field is required.');
  $this
    ->submitForm([
    'login[register][name]' => '',
    'login[register][mail]' => 'guest@example.com',
    'login[register][password][pass1]' => 'pass',
    'login[register][password][pass2]' => 'pass',
  ], 'Create account and continue');
  $this
    ->assertSession()
    ->pageTextContains('Username field is required.');
  $this
    ->submitForm([
    'login[register][name]' => 'User name',
    'login[register][mail]' => 'guest@example.com',
    'login[register][password][pass1]' => '',
    'login[register][password][pass2]' => '',
  ], 'Create account and continue');
  $this
    ->assertSession()
    ->pageTextContains('Password field is required.');
  $this
    ->submitForm([
    'login[register][name]' => 'User name double email',
    'login[register][mail]' => 'guest@example.com',
    'login[register][password][pass1]' => 'pass',
    'login[register][password][pass2]' => 'pass',
  ], 'Create account and continue');
  $this
    ->assertSession()
    ->pageTextContains('The email address guest@example.com is already taken.');
  $this
    ->submitForm([
    'login[register][name]' => 'User @#.``^ ù % name invalid',
    'login[register][mail]' => 'guest2@example.com',
    'login[register][password][pass1]' => 'pass',
    'login[register][password][pass2]' => 'pass',
  ], 'Create account and continue');
  $this
    ->assertSession()
    ->pageTextContains('The username contains an illegal character.');
  $this
    ->submitForm([
    'login[register][name]' => 'User name',
    'login[register][mail]' => 'guest2@example.com',
    'login[register][password][pass1]' => 'pass',
    'login[register][password][pass2]' => 'pass',
  ], 'Create account and continue');
  $this
    ->assertSession()
    ->pageTextContains('The username User name is already taken.');
}