public function AddToCartMultiAttributeTest::testRenderedVariationFields in Commerce Core 8.2
Tests that the cart refreshes rendered variation fields.
File
- modules/
cart/ tests/ src/ FunctionalJavascript/ AddToCartMultiAttributeTest.php, line 123
Class
- AddToCartMultiAttributeTest
- Tests the add to cart form.
Namespace
Drupal\Tests\commerce_cart\FunctionalJavascriptCode
public function testRenderedVariationFields() {
/** @var \Drupal\commerce_product\Entity\ProductVariationTypeInterface $variation_type */
$variation_type = ProductVariationType::load($this->variation
->bundle());
$color_attribute_values = $this
->createAttributeSet($variation_type, 'color', [
'cyan' => 'Cyan',
'magenta' => 'Magenta',
], TRUE);
/** @var \Drupal\commerce_product\Entity\ProductVariationInterface $variation1 */
$variation1 = $this
->createEntity('commerce_product_variation', [
'type' => 'default',
'sku' => 'RENDERED_VARIATION_TEST_CYAN',
'price' => [
'number' => 999,
'currency_code' => 'USD',
],
'attribute_color' => $color_attribute_values['cyan'],
]);
/** @var \Drupal\commerce_product\Entity\ProductVariationInterface $variation2 */
$variation2 = $this
->createEntity('commerce_product_variation', [
'type' => 'default',
'sku' => 'RENDERED_VARIATION_TEST_MAGENTA',
'price' => [
'number' => 999,
'currency_code' => 'USD',
],
'attribute_color' => $color_attribute_values['magenta'],
]);
$product = $this
->createEntity('commerce_product', [
'type' => 'default',
'title' => 'RENDERED_VARIATION_TEST',
'stores' => [
$this->store,
],
'variations' => [
$variation1,
$variation2,
],
]);
$this
->drupalGet($product
->toUrl());
$this
->assertSession()
->pageTextContains($variation1
->getSku());
$this
->getSession()
->getPage()
->selectFieldOption('purchased_entity[0][attributes][attribute_color]', 'Magenta');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertSession()
->pageTextContains($variation2
->getSku());
$this
->assertAttributeSelected('purchased_entity[0][attributes][attribute_color]', 'Magenta');
// Load variation2 directly via the url (?v=).
$this
->drupalGet($variation2
->toUrl());
$this
->assertSession()
->pageTextContains($variation2
->getSku());
$this
->assertAttributeSelected('purchased_entity[0][attributes][attribute_color]', 'Magenta');
$this
->getSession()
->getPage()
->selectFieldOption('purchased_entity[0][attributes][attribute_color]', 'Cyan');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertSession()
->pageTextContains($variation1
->getSku());
$this
->assertAttributeSelected('purchased_entity[0][attributes][attribute_color]', 'Cyan');
}