You are here

public function ProductVariationTypeTest::testEdit in Commerce Core 8.2

Tests editing a product variation type.

File

modules/product/tests/src/Functional/ProductVariationTypeTest.php, line 64

Class

ProductVariationTypeTest
Tests the product variation type UI.

Namespace

Drupal\Tests\commerce_product\Functional

Code

public function testEdit() {
  $this
    ->drupalGet('admin/commerce/config/product-variation-types/default/edit');
  $edit = [
    'label' => 'Default2',
    'attributes[color]' => 'color',
  ];
  $this
    ->submitForm($edit, t('Save'));
  $this
    ->assertSession()
    ->pageTextContains('Saved the Default2 product variation type.');
  $variation_type = ProductVariationType::load('default');
  $this
    ->assertEquals('Default2', $variation_type
    ->label());

  // Confirm that the attribute field has been created.
  $this
    ->drupalGet('admin/commerce/config/product-variation-types/default/edit/fields');
  $this
    ->assertSession()
    ->pageTextContains('attribute_color');
  $this
    ->drupalGet('admin/commerce/config/product-variation-types/default/edit');
  $edit = [
    'label' => 'Default2',
    'attributes[color]' => FALSE,
  ];
  $this
    ->submitForm($edit, t('Save'));
  $this
    ->assertSession()
    ->pageTextContains('Saved the Default2 product variation type.');

  // Confirm that the attribute field has been deleted.
  $this
    ->drupalGet('admin/commerce/config/product-variation-types/default/edit/fields');
  $this
    ->assertSession()
    ->pageTextNotContains('attribute_color');
}