You are here

public function ProductAttributeTest::testProductAttributeEditing in Commerce Core 8.2

Tests editing a product attribute.

File

modules/product/tests/src/Functional/ProductAttributeTest.php, line 56

Class

ProductAttributeTest
Create, edit, delete, and change product attributes.

Namespace

Drupal\Tests\commerce_product\Functional

Code

public function testProductAttributeEditing() {

  // Test the form without any variation types.
  $variation_type = ProductVariationType::load('default');
  $variation_type
    ->delete();
  $this
    ->createEntity('commerce_product_attribute', [
    'id' => 'color',
    'label' => 'Color',
  ]);
  $this
    ->drupalGet('admin/commerce/product-attributes/manage/color');
  $this
    ->assertSession()
    ->elementNotExists('css', '#edit-variation-types');
  $this
    ->submitForm([
    'label' => 'Colour',
    'elementType' => 'radios',
    'values[0][entity][name][0][value]' => 'Red',
  ], 'Save');
  $this
    ->assertSession()
    ->pageTextContains('Updated the Colour product attribute.');
  $this
    ->assertSession()
    ->addressMatches('/\\/admin\\/commerce\\/product-attributes$/');
  $attribute = ProductAttribute::load('color');
  $this
    ->assertEquals($attribute
    ->label(), 'Colour');
  $this
    ->assertEquals($attribute
    ->getElementType(), 'radios');
}