View source
<?php
namespace Drupal\Tests\commerce_migrate_commerce\Kernel\Migrate\commerce1;
use Drupal\Tests\commerce_migrate\Kernel\CommerceMigrateTestTrait;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\FieldStorageConfigInterface;
class FieldTest extends Commerce1TestBase {
use CommerceMigrateTestTrait;
protected static $modules = [
'address',
'comment',
'commerce_price',
'commerce_product',
'commerce_store',
'datetime',
'file',
'image',
'link',
'migrate_plus',
'node',
'path',
'profile',
'system',
'taxonomy',
'telephone',
'text',
];
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('commerce_product');
$this
->installEntitySchema('commerce_product_variation');
$this
->installEntitySchema('profile');
$this
->executeMigrations([
'commerce1_product_variation_type',
'commerce1_product_type',
'd7_field',
]);
}
protected function assertEntity($id, $type, $translatable, $cardinality, array $dependencies) {
list($entity_type) = explode('.', $id);
$field = FieldStorageConfig::load($id);
$this
->assertTrue($field instanceof FieldStorageConfigInterface);
$this
->assertSame($type, $field
->getType());
$this
->assertEquals($translatable, $field
->isTranslatable());
$this
->assertSame($entity_type, $field
->getTargetEntityTypeId());
$this
->assertSame($dependencies, $field
->getDependencies());
if ($cardinality === 1) {
$this
->assertFalse($field
->isMultiple());
}
else {
$this
->assertTrue($field
->isMultiple());
}
$this
->assertSame($cardinality, $field
->getCardinality());
}
public function testField() {
$field = FieldStorageConfig::load('comment.comment_body');
$this
->assertInstanceOf(FieldStorageConfigInterface::class, $field);
$field = FieldStorageConfig::load('commerce_product_variation.field_images');
$this
->assertTrue($field instanceof FieldStorageConfigInterface);
$field = FieldStorageConfig::load('commerce_product_variation.title_field');
$this
->assertNull($field);
$field = FieldStorageConfig::load('commerce_product_variation.commerce_price');
$this
->assertTrue($field instanceof FieldStorageConfigInterface);
$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);
$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);
$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);
$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);
$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);
$field = FieldStorageConfig::load('profile.address');
$this
->assertInstanceOf(FieldStorageConfigInterface::class, $field);
$this
->executeMigration('d7_field');
$migration = $this
->getMigration('d7_field');
$errors = $migration
->getIdMap()
->errorCount();
$this
->assertSame(0, $errors);
}
}