You are here

public function AddToCartMultilingualTest::testProductVariationTitleWidget in Commerce Core 8.2

Tests the title widget has translated variation title.

File

modules/cart/tests/src/FunctionalJavascript/AddToCartMultilingualTest.php, line 229

Class

AddToCartMultilingualTest
Tests the add to cart form for multilingual.

Namespace

Drupal\Tests\commerce_cart\FunctionalJavascript

Code

public function testProductVariationTitleWidget() {
  $order_item_form_display = EntityFormDisplay::load('commerce_order_item.default.add_to_cart');
  $order_item_form_display
    ->setComponent('purchased_entity', [
    'type' => 'commerce_product_variation_title',
  ]);
  $order_item_form_display
    ->save();
  $this
    ->drupalGet($this->product
    ->toUrl());
  $this
    ->assertSession()
    ->selectExists('purchased_entity[0][variation]');
  $this
    ->assertAttributeSelected('purchased_entity[0][variation]', 'My Super Product - Red, Small');
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Add to cart');

  // Change the site language.
  $this
    ->config('system.site')
    ->set('default_langcode', 'fr')
    ->save();
  $this
    ->rebuildContainer();
  $this
    ->drupalGet($this->product
    ->getTranslation('fr')
    ->toUrl());

  // Use AJAX to change the size to Medium, keeping the color on Red.
  $this
    ->assertAttributeSelected('purchased_entity[0][variation]', 'Mon super produit - FR Red, FR Small');
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('purchased_entity[0][variation]', 'Mon super produit - FR Red, FR Medium');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assertAttributeSelected('purchased_entity[0][variation]', 'Mon super produit - FR Red, FR Medium');
  $this
    ->assertSession()
    ->pageTextContains('Mon super produit - FR Red, FR Medium');

  // Use AJAX to change the color to Blue, keeping the size on Medium.
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('purchased_entity[0][variation]', 'Mon super produit - FR Blue, FR Medium');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assertAttributeSelected('purchased_entity[0][variation]', 'Mon super produit - FR Blue, FR Medium');
  $this
    ->assertSession()
    ->pageTextContains('Mon super produit - FR Blue, FR Medium');
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Add to cart');
  $this->cart = Order::load($this->cart
    ->id());
  $order_items = $this->cart
    ->getItems();
  $this
    ->assertOrderItemInOrder($this->variations[0]
    ->getTranslation('fr'), $order_items[0]);
  $this
    ->assertOrderItemInOrder($this->variations[5]
    ->getTranslation('fr'), $order_items[1]);
}