You are here

public function ProductTypeTest::testDuplicate in Commerce Core 8.2

Tests duplicating a product type.

File

modules/product/tests/src/Functional/ProductTypeTest.php, line 194

Class

ProductTypeTest
Tests the product type UI.

Namespace

Drupal\Tests\commerce_product\Functional

Code

public function testDuplicate() {
  $this
    ->drupalGet('admin/commerce/config/product-types/default/duplicate');
  $this
    ->assertSession()
    ->fieldValueEquals('label', 'Default');
  $edit = [
    'label' => 'Default2',
    'id' => 'default2',
    'multipleVariations' => FALSE,
  ];
  $this
    ->submitForm($edit, t('Save'));
  $this
    ->assertSession()
    ->pageTextContains('The product type Default2 has been successfully saved.');

  // Confirm that the original product type is unchanged.
  $product_type = ProductType::load('default');
  $this
    ->assertNotEmpty($product_type);
  $this
    ->assertEquals('Default', $product_type
    ->label());

  // Confirm that the new product type has the expected data.
  $product_type = ProductType::load('default2');
  $this
    ->assertNotEmpty($product_type);
  $this
    ->assertEquals('Default2', $product_type
    ->label());
  $this
    ->assertFalse($product_type
    ->allowsMultipleVariations());

  // Confirm that the form display is correct.
  $form_display = commerce_get_entity_display('commerce_product', 'default2', 'form');
  $component = $form_display
    ->getComponent('variations');
  $this
    ->assertNotEmpty($component);
  $this
    ->assertEquals('commerce_product_single_variation', $component['type']);
}