MigrateFieldTest.php in Inline Entity Form 8
File
tests/src/Kernel/Migrate/MigrateFieldTest.php
View source
<?php
namespace Drupal\Tests\inline_entity_form\Kernel\Migrate;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\FieldStorageConfigInterface;
class MigrateFieldTest extends MigrateTestBase {
public static $modules = [
'node',
'text',
];
protected function setUp() {
parent::setUp();
$this
->executeMigration('d7_field');
}
protected function assertEntity($id, $expected_type, $expected_translatable, $expected_cardinality) {
list($expected_entity_type, $expected_name) = explode('.', $id);
$field = FieldStorageConfig::load($id);
$this
->assertInstanceOf(FieldStorageConfigInterface::class, $field);
$this
->assertEquals($expected_name, $field
->getName());
$this
->assertEquals($expected_type, $field
->getType());
$this
->assertEquals($expected_translatable, $field
->isTranslatable());
$this
->assertEquals($expected_entity_type, $field
->getTargetEntityTypeId());
if ($expected_cardinality === 1) {
$this
->assertFalse($field
->isMultiple());
}
else {
$this
->assertTrue($field
->isMultiple());
}
$this
->assertEquals($expected_cardinality, $field
->getCardinality());
}
public function testFields() {
$this
->assertEntity('node.body', 'text_with_summary', TRUE, 1);
$this
->assertEntity('node.field_single', 'entity_reference', TRUE, 1);
$this
->assertEntity('node.field_multiple', 'entity_reference', TRUE, 1);
$field = FieldStorageConfig::load('node.field_single');
$this
->assertEquals('node', $field
->getSetting('target_type'));
$field = FieldStorageConfig::load('node.field_multiple');
$this
->assertEquals('node', $field
->getSetting('target_type'));
}
}