public function ProductAttributeTest::testProductAttributeCreation in Commerce Core 8.2
Tests creation of a product attribute.
File
- modules/
product/ tests/ src/ Functional/ ProductAttributeTest.php, line 29
Class
- ProductAttributeTest
- Create, edit, delete, and change product attributes.
Namespace
Drupal\Tests\commerce_product\FunctionalCode
public function testProductAttributeCreation() {
// Test the form without any variation types.
$variation_type = ProductVariationType::load('default');
$variation_type
->delete();
$this
->drupalGet('admin/commerce/product-attributes');
$this
->getSession()
->getPage()
->clickLink('Add product attribute');
$this
->assertSession()
->elementNotExists('css', '#edit-variation-types');
$this
->submitForm([
'label' => 'Size',
'elementType' => 'commerce_product_rendered_attribute',
// Setting the 'id' can fail if focus switches to another field.
// This is a bug in the machine name JS that can be reproduced manually.
'id' => 'size',
], 'Save');
$this
->assertSession()
->pageTextContains('Created the Size product attribute.');
$this
->assertSession()
->addressMatches('/\\/admin\\/commerce\\/product-attributes\\/manage\\/size$/');
$attribute = ProductAttribute::load('size');
$this
->assertEquals($attribute
->label(), 'Size');
$this
->assertEquals($attribute
->getElementType(), 'commerce_product_rendered_attribute');
}