View source
<?php
namespace Drupal\Tests\commerce_migrate_ubercart\Kernel\Migrate\uc7;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\FieldConfigInterface;
use Drupal\Tests\commerce_migrate\Kernel\CommerceMigrateTestTrait;
class AttributeFieldInstanceTest extends Ubercart7TestBase {
use CommerceMigrateTestTrait;
public static $modules = [
'path',
'commerce_price',
'commerce_product',
'commerce_store',
'text',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('commerce_product');
$this
->installEntitySchema('commerce_product_variation');
$this
->installConfig([
'commerce_product',
]);
$this
->executeMigrations([
'uc_attribute_field',
'uc_product_attribute',
'uc_attribute_field_instance',
]);
}
protected function assertEntity($name, $type, $bundle, $label, $description, $translatable) {
$id = 'commerce_product_variation.default.attribute_' . $name;
$field = FieldConfig::load($id);
$this
->assertTrue($field instanceof FieldConfigInterface);
$this
->assertSame($type, $field
->getType());
$this
->assertSame($bundle, $field
->getTargetBundle());
$this
->assertSame($label, $field
->label());
$this
->assertSame($description, $field
->getDescription());
$this
->assertSame('default:commerce_product_attribute_value', $field
->getSetting('handler'));
$this
->assertSame([
'target_bundles' => [
$name,
],
], $field
->getSetting('handler_settings'));
$this
->assertSame('commerce_product_attribute_value', $field
->getSetting('target_type'));
$this
->assertEquals($translatable, $field
->isTranslatable());
$this
->assertSame('commerce_product_variation', $field
->getTargetEntityTypeId());
}
public function testAttributeInstance() {
$this
->assertEntity('size', 'entity_reference', 'default', 'Size', 'Volume', TRUE);
$this
->assertEntity('extra', 'entity_reference', 'default', 'Extra', '', TRUE);
$this
->assertEntity('attribute_with_name_', 'entity_reference', 'default', 'Long name test', '', TRUE);
$this
->assertEntity('duration', 'entity_reference', 'default', 'Duration', '', TRUE);
}
}