public function FieldTest::testField in Commerce Migrate 8.2
Same name and namespace in other branches
- 3.1.x modules/commerce/tests/src/Kernel/Migrate/commerce1/FieldTest.php \Drupal\Tests\commerce_migrate_commerce\Kernel\Migrate\commerce1\FieldTest::testField()
- 3.0.x modules/commerce/tests/src/Kernel/Migrate/commerce1/FieldTest.php \Drupal\Tests\commerce_migrate_commerce\Kernel\Migrate\commerce1\FieldTest::testField()
Test field migration from Drupal 7 to Drupal 8.
File
- modules/
commerce/ tests/ src/ Kernel/ Migrate/ commerce1/ FieldTest.php, line 95
Class
- FieldTest
- Tests field migration.
Namespace
Drupal\Tests\commerce_migrate_commerce\Kernel\Migrate\commerce1Code
public function testField() {
/** @var \Drupal\field\FieldStorageConfigInterface $field */
$field = FieldStorageConfig::load('comment.comment_body');
$this
->assertInstanceOf(FieldStorageConfigInterface::class, $field);
// Commerce product variation field storage.
$field = FieldStorageConfig::load('commerce_product_variation.field_images');
$this
->assertTrue($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('commerce_product_variation.title_field');
$this
->assertNull($field);
// The default price on product in D8 is a base field without a field
// storage so migrating this could be skipped. However, the source product
// may have additional price field so migrate them all.
// @TODO find a way to not migrate the base price field storage.
$field = FieldStorageConfig::load('commerce_product_variation.commerce_price');
$this
->assertTrue($field instanceof FieldStorageConfigInterface);
// Commerce product variation attribute field storage.
$dependencies = [
'module' => [
'commerce_product',
],
];
$this
->assertEntity('commerce_product_variation.attribute_bag_size', 'entity_reference', TRUE, 1, $dependencies);
$this
->assertEntity('commerce_product_variation.attribute_color', 'entity_reference', TRUE, 1, $dependencies);
$this
->assertEntity('commerce_product_variation.attribute_hat_size', 'entity_reference', TRUE, 1, $dependencies);
$this
->assertEntity('commerce_product_variation.attribute_shoe_size', 'entity_reference', TRUE, 1, $dependencies);
$this
->assertEntity('commerce_product_variation.attribute_storage_capacity', 'entity_reference', TRUE, 1, $dependencies);
$this
->assertEntity('commerce_product_variation.attribute_top_size', 'entity_reference', TRUE, 1, $dependencies);
// Commerce product field storage.
$field = FieldStorageConfig::load('commerce_product.body');
$this
->assertTrue($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('commerce_product.field_brand');
$this
->assertTrue($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('commerce_product.field_category');
$this
->assertTrue($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('commerce_product.field_collection');
$this
->assertTrue($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('commerce_product.field_gender');
$this
->assertTrue($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('commerce_product.field_product');
$this
->assertTrue($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('commerce_product.title_field');
$this
->assertNull($field);
// Commerce product field storage should not be duplicated on nodes.
$field = FieldStorageConfig::load('node.field_brand');
$this
->assertFalse($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('node.field_category');
$this
->assertFalse($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('node.field_collection');
$this
->assertFalse($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('node.field_gender');
$this
->assertFalse($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('node.field_product');
$this
->assertFalse($field instanceof FieldStorageConfigInterface);
// Node field storage.
$field = FieldStorageConfig::load('node.field_blog_category');
$this
->assertTrue($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('node.body');
$this
->assertTrue($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('node.title_field');
$this
->assertNull($field);
$field = FieldStorageConfig::load('node.field_headline');
$this
->assertTrue($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('node.field_image');
$this
->assertTrue($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('node.field_link');
$this
->assertTrue($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('node.field_tags');
$this
->assertTrue($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('node.field_tagline');
$this
->assertTrue($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('node.title_field');
$this
->assertNull($field);
// Node only field storage should not be duplicated on commerce products.
$field = FieldStorageConfig::load('commerce_product.field_blog_category');
$this
->assertFalse($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('commerce_product.field_headline');
$this
->assertFalse($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('commerce_product.field_image');
$this
->assertFalse($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('commerce_product.field_link');
$this
->assertFalse($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('commerce_product.field_tags');
$this
->assertFalse($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('commerce_product.field_tagline');
$this
->assertFalse($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('taxonomy_term.field_image');
$this
->assertTrue($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('taxonomy_term.field_category_color');
$this
->assertTrue($field instanceof FieldStorageConfigInterface);
// Address field storage.
$field = FieldStorageConfig::load('profile.address');
$this
->assertInstanceOf(FieldStorageConfigInterface::class, $field);
// Test that a rerun of the migration does not cause errors.
$this
->executeMigration('d7_field');
$migration = $this
->getMigration('d7_field');
$errors = $migration
->getIdMap()
->errorCount();
$this
->assertSame(0, $errors);
}