public function AddToCartFormTest::testRenderedAttributeElement in Commerce Core 8.2
Tests that the add to cart form renders an attribute entity.
File
- modules/
cart/ tests/ src/ Functional/ AddToCartFormTest.php, line 162
Class
- AddToCartFormTest
- Tests the add to cart form.
Namespace
Drupal\Tests\commerce_cart\FunctionalCode
public function testRenderedAttributeElement() {
/** @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);
$color_attribute_values['cyan']
->set('rendered_test', 'Cyan (Rendered)')
->save();
$color_attribute_values['cyan']
->save();
$color_attribute_values['magenta']
->set('rendered_test', 'Magenta (Rendered)')
->save();
$color_attribute_values['magenta']
->save();
$color_attribute = ProductAttribute::load($color_attribute_values['cyan']
->getAttributeId());
$variation1 = $this
->createEntity('commerce_product_variation', [
'type' => 'default',
'sku' => $this
->randomMachineName(),
'price' => [
'number' => 999,
'currency_code' => 'USD',
],
'attribute_color' => $color_attribute_values['cyan'],
]);
$variation2 = $this
->createEntity('commerce_product_variation', [
'type' => 'default',
'sku' => $this
->randomMachineName(),
'price' => [
'number' => 999,
'currency_code' => 'USD',
],
'attribute_color' => $color_attribute_values['magenta'],
]);
$product = $this
->createEntity('commerce_product', [
'type' => 'default',
'title' => $this
->randomMachineName(),
'stores' => [
$this->store,
],
'variations' => [
$variation1,
$variation2,
],
]);
$this
->drupalGet($product
->toUrl());
$this
->assertAttributeExists('purchased_entity[0][attributes][attribute_color]', $color_attribute_values['cyan']
->id());
$color_attribute
->set('elementType', 'commerce_product_rendered_attribute')
->save();
$this
->drupalGet($product
->toUrl());
$this
->assertSession()
->pageTextContains('Cyan (Rendered)');
$this
->assertSession()
->pageTextContains('Magenta (Rendered)');
}