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 FieldWidgetSettingsTest extends Ubercart6TestBase {
protected static $modules = [
'commerce_price',
'commerce_product',
'commerce_store',
'field',
'migrate_plus',
'path',
];
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('commerce_product');
$this
->installConfig([
'commerce_product',
]);
$this
->migrateFields();
}
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 testWidgetSettings() {
$this
->assertEntity('node.page.default', 'node', 'page');
$this
->assertComponent('node.page.default', 'body', 'text_textarea_with_summary', 121);
$this
->assertComponent('node.page.default', 'field_integer', 'number', 31);
$this
->assertEntity('commerce_product.default.default', 'commerce_product', 'default');
$this
->assertComponent('commerce_product.product.default', 'field_image_cache', 'image_image', -2);
$this
->assertComponent('commerce_product.product.default', 'field_integer', 'number', 33);
$this
->assertComponent('commerce_product.product.default', 'field_sustain', 'text_textarea', 31);
$this
->assertComponent('commerce_product.ship.default', 'field_engine', 'text_textarea', 31);
$this
->assertComponent('commerce_product.ship.default', 'field_image_cache', 'image_image', -2);
$this
->assertComponent('commerce_product.ship.default', 'field_integer', 'number', 33);
}
}