You are here

public function CheckoutOrderTest::testMultilingualRegisterOrderCheckout in Commerce Core 8.2

Tests the user gets created during registration in the current language.

File

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

Class

CheckoutOrderTest
Tests the checkout of an order.

Namespace

Drupal\Tests\commerce_checkout\Functional

Code

public function testMultilingualRegisterOrderCheckout() {
  \Drupal::service('module_installer')
    ->install([
    'language',
  ]);
  ConfigurableLanguage::createFromLangcode('fr')
    ->save();
  $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('/fr/product/' . $this->product
    ->id());
  $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');

  // Assert created user account values.
  $users = \Drupal::entityTypeManager()
    ->getStorage('user')
    ->loadByProperties([
    'mail' => 'guest@example.com',
  ]);

  /** @var \Drupal\user\UserInterface $user */
  $user = reset($users);
  $this
    ->assertEquals('User name', $user
    ->label());
  $this
    ->assertEquals('fr', $user
    ->language()
    ->getId());
  $this
    ->assertEquals('fr', $user
    ->getPreferredLangcode());
  $this
    ->assertEquals('fr', $user
    ->getPreferredAdminLangcode());
}