public function ProductVariationTypeTest::testDuplicate in Commerce Core 8.2
Tests duplicating a product variation type.
File
- modules/
product/ tests/ src/ Functional/ ProductVariationTypeTest.php, line 95
Class
- ProductVariationTypeTest
- Tests the product variation type UI.
Namespace
Drupal\Tests\commerce_product\FunctionalCode
public function testDuplicate() {
$this
->drupalGet('admin/commerce/config/product-variation-types/default/edit');
$edit = [
'attributes[color]' => 'color',
'attributes[size]' => 'size',
];
$this
->submitForm($edit, t('Save'));
$this
->drupalGet('admin/commerce/config/product-variation-types/default/duplicate');
$this
->assertSession()
->fieldValueEquals('label', 'Default');
$this
->assertSession()
->checkboxChecked('attributes[color]');
$this
->assertSession()
->checkboxChecked('attributes[size]');
$edit = [
'label' => 'Default2',
'id' => 'default2',
'attributes[color]' => 'color',
'attributes[size]' => FALSE,
];
$this
->submitForm($edit, t('Save'));
$this
->assertSession()
->pageTextContains('Saved the Default2 product variation type.');
// Confirm that the original variation type is unchanged.
$variation_type = ProductVariationType::load('default');
$this
->assertNotEmpty($variation_type);
$this
->assertEquals('Default', $variation_type
->label());
// Confirm that the new variation type has the expected data.
$variation_type = ProductVariationType::load('default2');
$this
->assertNotEmpty($variation_type);
$this
->assertEquals('Default2', $variation_type
->label());
$this
->assertEquals('default', $variation_type
->getOrderItemTypeId());
// Confirm that only the attribute from the duplicate form was created.
$this
->drupalGet('admin/commerce/config/product-variation-types/default2/edit/fields');
$this
->assertSession()
->pageTextContains('attribute_color');
$this
->assertSession()
->pageTextNotContains('attribute_size');
}