View source
<?php
namespace Drupal\Tests\commerce_migrate_ubercart\Kernel\Migrate\uc7;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\Tests\commerce_migrate\Kernel\CommerceMigrateTestTrait;
class AttributeFieldTest extends Ubercart7TestBase {
use CommerceMigrateTestTrait;
protected static $modules = [
'commerce_product',
'commerce_price',
];
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('commerce_product_variation');
$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_size', 'entity_reference', TRUE, 1, $dependencies);
$this
->assertEntity('commerce_product_variation.attribute_extra', 'entity_reference', TRUE, -1, $dependencies);
$this
->assertEntity('commerce_product_variation.attribute_attribute_with_name_', 'entity_reference', TRUE, 1, $dependencies);
$this
->assertEntity('commerce_product_variation.attribute_duration', 'entity_reference', TRUE, 1, $dependencies);
}
}