View source
<?php
namespace Drupal\Tests\commerce_migrate_ubercart\Kernel\Migrate\uc6;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\Tests\commerce_migrate\Kernel\CommerceMigrateTestTrait;
class AttributeFieldTest extends Ubercart6TestBase {
use CommerceMigrateTestTrait;
public static $modules = [
'commerce_price',
'commerce_product',
'commerce_store',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('commerce_product_variation');
$this
->installEntitySchema('commerce_store');
$this
->executeMigration('uc_attribute_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 testAttribute() {
$dependencies = [
'module' => [
'commerce_product',
],
];
$this
->assertEntity('commerce_product_variation.attribute_design', 'entity_reference', TRUE, 1, $dependencies);
$this
->assertEntity('commerce_product_variation.attribute_color', 'entity_reference', TRUE, -1, $dependencies);
$this
->assertEntity('commerce_product_variation.attribute_model_size_attribute', 'entity_reference', TRUE, 1, $dependencies);
$this
->assertEntity('commerce_product_variation.attribute_name', 'entity_reference', TRUE, 1, $dependencies);
}
}