View source
<?php
namespace Drupal\Tests\commerce_migrate_ubercart\Kernel\Migrate\uc6;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
class AttributeFieldInstanceWidgetSettingsTest extends Ubercart6TestBase {
public static $modules = [
'commerce_price',
'commerce_product',
'commerce_store',
'path',
];
protected function setUp() {
parent::setUp();
$this
->migrateAttributes();
}
protected function assertEntity($id, $expected_entity_type, $expected_bundle) {
$entity = EntityFormDisplay::load($id);
$this
->assertInstanceOf(EntityFormDisplayInterface::class, $entity);
$this
->assertSame($expected_entity_type, $entity
->getTargetEntityTypeId());
$this
->assertSame($expected_bundle, $entity
->getTargetBundle());
}
protected function assertComponent($display_id, $component_id, $widget_type, $weight) {
$component = EntityFormDisplay::load($display_id)
->getComponent($component_id);
$this
->assertTrue(is_array($component));
$this
->assertSame($widget_type, $component['type']);
$this
->assertSame($weight, $component['weight']);
}
public function testAttributeWidgetSettings() {
$this
->assertEntity('commerce_product_variation.default.default', 'commerce_product_variation', 'default');
$this
->assertComponent('commerce_product_variation.default.default', 'attribute_color', 'boolean_checkbox', 500);
$this
->assertComponent('commerce_product_variation.default.default', 'attribute_design', 'options_buttons', 0);
$this
->assertComponent('commerce_product_variation.default.default', 'attribute_model_size_attribute', 'options_select', 400);
$display = EntityFormDisplay::load('commerce_product_variation.default.default');
$this
->assertInstanceOf(EntityFormDisplay::class, $display);
$component = $display
->getComponent('attribute_name');
$this
->assertNull($component);
}
}