public function AddToCartMultilingualTest::testProductVariationAttributesWidget in Commerce Core 8.2
Tests that the attribute widget uses translated items.
File
- modules/
cart/ tests/ src/ FunctionalJavascript/ AddToCartMultilingualTest.php, line 166
Class
- AddToCartMultilingualTest
- Tests the add to cart form for multilingual.
Namespace
Drupal\Tests\commerce_cart\FunctionalJavascriptCode
public function testProductVariationAttributesWidget() {
$this
->drupalGet($this->product
->toUrl());
$this
->assertAttributeSelected('purchased_entity[0][attributes][attribute_color]', 'Red');
$this
->assertAttributeSelected('purchased_entity[0][attributes][attribute_size]', 'Small');
$this
->assertAttributeExists('purchased_entity[0][attributes][attribute_color]', $this->colorAttributes['blue']
->id());
$this
->assertAttributeExists('purchased_entity[0][attributes][attribute_size]', $this->sizeAttributes['medium']
->id());
$this
->assertAttributeExists('purchased_entity[0][attributes][attribute_size]', $this->sizeAttributes['large']
->id());
$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
->getSession()
->getPage()
->selectFieldOption('purchased_entity[0][attributes][attribute_size]', 'FR Medium');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertAttributeSelected('purchased_entity[0][attributes][attribute_color]', 'FR Red');
$this
->assertAttributeSelected('purchased_entity[0][attributes][attribute_size]', 'FR Medium');
$this
->assertAttributeExists('purchased_entity[0][attributes][attribute_color]', $this->colorAttributes['blue']
->id());
$this
->assertAttributeExists('purchased_entity[0][attributes][attribute_size]', $this->sizeAttributes['small']
->id());
$this
->assertAttributeExists('purchased_entity[0][attributes][attribute_size]', $this->sizeAttributes['large']
->id());
// Use AJAX to change the color to Blue, keeping the size on Medium.
$this
->getSession()
->getPage()
->selectFieldOption('purchased_entity[0][attributes][attribute_color]', 'FR Blue');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertAttributeSelected('purchased_entity[0][attributes][attribute_color]', 'FR Blue');
$this
->assertAttributeSelected('purchased_entity[0][attributes][attribute_size]', 'FR Medium');
$this
->assertAttributeExists('purchased_entity[0][attributes][attribute_color]', $this->colorAttributes['red']
->id());
$this
->assertAttributeExists('purchased_entity[0][attributes][attribute_size]', $this->sizeAttributes['small']
->id());
$this
->assertAttributeDoesNotExist('purchased_entity[0][attributes][attribute_size]', $this->sizeAttributes['large']
->id());
$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]);
}