View source
<?php
namespace Drupal\Tests\commerce_migrate_ubercart\Kernel\Migrate\uc7;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
class FieldWidgetSettingsTest extends Ubercart7TestBase {
protected static $modules = [
'comment',
'commerce_price',
'commerce_product',
'commerce_store',
'image',
'migrate_plus',
'node',
'path',
'taxonomy',
'text',
];
protected function setUp() : void {
parent::setUp();
$this
->migrateFields();
$this
->executeMigrations([
'd7_view_modes',
'd7_field_formatter_settings',
'd7_field_instance_widget_settings',
]);
}
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', -4);
$this
->assertComponent('node.page.default', 'field_number', 'number', -3);
$this
->assertEntity('node.article.default', 'node', 'article');
$this
->assertComponent('node.article.default', 'field_image', 'image_image', -1);
$this
->assertComponent('node.article.default', 'field_tags', 'entity_reference_autocomplete', -4);
$this
->assertEntity('commerce_product.default.default', 'commerce_product', 'default');
$this
->assertEntity('commerce_product.product.default', 'commerce_product', 'product');
$this
->assertComponent('commerce_product.product.default', 'field_sustainability', 'string_textfield', 1);
$this
->assertComponent('commerce_product.product.default', 'taxonomy_catalog', 'options_select', -2);
$this
->assertComponent('commerce_product.product.default', 'uc_product_image', 'image_image', -3);
$this
->assertEntity('taxonomy_term.catalog.default', 'taxonomy_term', 'catalog');
$this
->assertComponent('taxonomy_term.catalog.default', 'uc_catalog_image', 'image_image', 1);
}
}