View source
<?php
namespace Drupal\Tests\commerce_migrate_commerce\Kernel\Migrate\commerce1;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\FieldConfigInterface;
use Drupal\Tests\commerce_migrate\Kernel\CommerceMigrateTestTrait;
class FieldInstanceTest extends Commerce1TestBase {
use CommerceMigrateTestTrait;
public static $modules = [
'comment',
'commerce_price',
'commerce_product',
'commerce_store',
'datetime',
'file',
'image',
'link',
'menu_ui',
'migrate_plus',
'node',
'path',
'profile',
'system',
'taxonomy',
'telephone',
'text',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('commerce_store');
$this
->migrateFields();
}
protected function assertEntity($id, $expected_label, $expected_field_type, $is_required, $expected_translatable) {
list($expected_entity_type, $expected_bundle, $expected_name) = explode('.', $id);
$field = FieldConfig::load($id);
$this
->assertInstanceOf(FieldConfigInterface::class, $field);
$this
->assertEquals($expected_label, $field
->label());
$this
->assertEquals($expected_field_type, $field
->getType());
$this
->assertEquals($expected_entity_type, $field
->getTargetEntityTypeId());
$this
->assertEquals($expected_bundle, $field
->getTargetBundle());
$this
->assertEquals($expected_name, $field
->getName());
$this
->assertEquals($is_required, $field
->isRequired());
$this
->assertEquals($expected_entity_type . '.' . $expected_name, $field
->getFieldStorageDefinition()
->id());
$this
->assertEquals($expected_translatable, $field
->isTranslatable());
}
protected function assertLinkFields($id, $title_setting) {
$field = FieldConfig::load($id);
$this
->assertSame($title_setting, $field
->getSetting('title'));
}
public function testFieldInstances() {
$this
->assertEntity('comment.comment_node_ad_push.comment_body', 'Comment', 'text_long', TRUE, FALSE);
$this
->assertEntity('comment.comment_node_bags_cases.comment_body', 'Comment', 'text_long', TRUE, FALSE);
$this
->assertEntity('comment.comment_node_blog_post.comment_body', 'Comment', 'text_long', TRUE, FALSE);
$this
->assertEntity('comment.comment_node_drinks.comment_body', 'Comment', 'text_long', TRUE, FALSE);
$this
->assertEntity('comment.comment_node_hats.comment_body', 'Comment', 'text_long', TRUE, FALSE);
$this
->assertEntity('comment.comment_node_page.comment_body', 'Comment', 'text_long', TRUE, FALSE);
$this
->assertEntity('comment.comment_node_shoes.comment_body', 'Comment', 'text_long', TRUE, FALSE);
$this
->assertEntity('comment.comment_node_slideshow.comment_body', 'Comment', 'text_long', TRUE, FALSE);
$this
->assertEntity('comment.comment_node_storage_devices.comment_body', 'Comment', 'text_long', TRUE, FALSE);
$this
->assertEntity('comment.comment_node_tops.comment_body', 'Comment', 'text_long', TRUE, FALSE);
$this
->assertEntity('commerce_product.bags_cases.body', 'Body', 'text_with_summary', FALSE, FALSE);
$this
->assertEntity('commerce_product.bags_cases.field_brand', 'Brand', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.bags_cases.field_category', 'Category', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.bags_cases.field_collection', 'Collection', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.bags_cases.field_gender', 'Gender', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.bags_cases.field_product', 'Product variations', 'entity_reference', TRUE, FALSE);
$this
->assertEntity('commerce_product.drinks.body', 'Body', 'text_with_summary', FALSE, FALSE);
$this
->assertEntity('commerce_product.drinks.field_brand', 'Brand', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.drinks.field_category', 'Category', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.drinks.field_collection', 'Collection', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.drinks.field_gender', 'Gender', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.drinks.field_product', 'Product variations', 'entity_reference', TRUE, FALSE);
$this
->assertEntity('commerce_product.hats.body', 'Body', 'text_with_summary', FALSE, FALSE);
$this
->assertEntity('commerce_product.hats.field_brand', 'Brand', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.hats.field_category', 'Category', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.hats.field_collection', 'Collection', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.hats.field_gender', 'Gender', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.hats.field_product', 'Product variations', 'entity_reference', TRUE, FALSE);
$this
->assertEntity('commerce_product.shoes.body', 'Body', 'text_with_summary', FALSE, FALSE);
$this
->assertEntity('commerce_product.shoes.field_brand', 'Brand', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.shoes.field_category', 'Category', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.shoes.field_collection', 'Collection', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.shoes.field_gender', 'Gender', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.shoes.field_product', 'Product variations', 'entity_reference', TRUE, FALSE);
$this
->assertEntity('commerce_product.storage_devices.body', 'Body', 'text_with_summary', FALSE, FALSE);
$this
->assertEntity('commerce_product.storage_devices.field_brand', 'Brand', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.storage_devices.field_category', 'Category', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.storage_devices.field_collection', 'Collection', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.storage_devices.field_gender', 'Gender', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.storage_devices.field_product', 'Product variations', 'entity_reference', TRUE, FALSE);
$this
->assertEntity('commerce_product.tops.body', 'Body', 'text_with_summary', FALSE, FALSE);
$this
->assertEntity('commerce_product.tops.field_brand', 'Brand', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.tops.field_category', 'Category', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.tops.field_collection', 'Collection', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.tops.field_gender', 'Gender', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product.tops.field_product', 'Product variations', 'entity_reference', TRUE, FALSE);
$this
->assertEntity('commerce_product_variation.bags_cases.commerce_price', 'Price', 'commerce_price', TRUE, FALSE);
$this
->assertEntity('commerce_product_variation.bags_cases.field_images', 'Images', 'image', FALSE, TRUE);
$this
->assertEntity('commerce_product_variation.drinks.field_images', 'Images', 'image', FALSE, TRUE);
$this
->assertEntity('commerce_product_variation.hats.field_images', 'Images', 'image', FALSE, TRUE);
$this
->assertEntity('commerce_product_variation.shoes.field_images', 'Images', 'image', FALSE, TRUE);
$this
->assertEntity('commerce_product_variation.storage_devices.field_images', 'Images', 'image', FALSE, TRUE);
$this
->assertEntity('commerce_product_variation.tops.field_images', 'Images', 'image', FALSE, TRUE);
$this
->assertEntity('commerce_product_variation.bags_cases.attribute_bag_size', 'Size', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product_variation.bags_cases.attribute_color', 'Color', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product_variation.drinks.attribute_color', 'Color', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product_variation.hats.attribute_color', 'Color', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product_variation.hats.attribute_hat_size', 'Size', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product_variation.shoes.attribute_color', 'Color', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product_variation.shoes.attribute_shoe_size', 'Size', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product_variation.storage_devices.attribute_storage_capacity', 'Capacity', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product_variation.tops.attribute_color', 'Color', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('commerce_product_variation.tops.attribute_top_size', 'Size', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('node.page.body', 'Body', 'text_with_summary', FALSE, FALSE);
$this
->assertEntity('node.blog_post.body', 'Description', 'text_with_summary', FALSE, FALSE);
$this
->assertEntity('node.blog_post.field_blog_category', 'Category', 'entity_reference', FALSE, FALSE);
$this
->assertEntity('node.blog_post.field_image', 'Image', 'image', TRUE, FALSE);
$this
->assertEntity('node.slideshow.field_headline', 'Headline', 'string', FALSE, FALSE);
$this
->assertEntity('node.slideshow.field_image', 'Image', 'image', TRUE, FALSE);
$this
->assertLinkFields('node.slideshow.field_link', DRUPAL_DISABLED);
$this
->assertEntity('node.ad_push.field_image', 'Image', 'image', TRUE, FALSE);
$this
->assertLinkFields('node.ad_push.field_link', DRUPAL_DISABLED);
$migration = $this
->getMigration('d7_field_instance');
$errors = $migration
->getIdMap()
->errorCount();
$this
->assertSame(0, $errors);
}
}