View source
<?php
namespace Drupal\Tests\taxonomy\Kernel\Migrate\d6;
use Drupal\field\Entity\FieldConfig;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
class MigrateVocabularyFieldInstanceTest extends MigrateDrupal6TestBase {
public static $modules = [
'taxonomy',
'menu_ui',
];
protected function setUp() {
parent::setUp();
$this
->migrateContentTypes();
$this
->installEntitySchema('taxonomy_term');
$this
->executeMigrations([
'd6_node_type',
'd6_taxonomy_vocabulary',
'd6_vocabulary_field',
]);
}
public function testVocabularyFieldInstance() {
$this
->executeMigration('d6_vocabulary_field_instance');
$field_id = 'node.article.field_tags';
$field = FieldConfig::load($field_id);
$this
->assertSame($field_id, $field
->id(), 'Field instance exists on article bundle.');
$this
->assertSame('Tags', $field
->label());
$this
->assertTrue($field
->isRequired(), 'Field is required');
$this
->assertFalse($field
->isTranslatable());
$field_id = 'node.page.field_tags';
$field = FieldConfig::load($field_id);
$this
->assertSame($field_id, $field
->id(), 'Field instance exists on page bundle.');
$this
->assertSame('Tags', $field
->label());
$this
->assertTrue($field
->isRequired(), 'Field is required');
$this
->assertFalse($field
->isTranslatable());
$settings = $field
->getSettings();
$this
->assertSame('default:taxonomy_term', $settings['handler'], 'The handler plugin ID is correct.');
$this
->assertSame([
'field_tags',
], $settings['handler_settings']['target_bundles'], 'The target_bundles handler setting is correct.');
$this
->assertSame(TRUE, $settings['handler_settings']['auto_create'], 'The "auto_create" setting is correct.');
$this
->assertSame([
[
'node',
'article',
'field_tags',
],
], $this
->getMigration('d6_vocabulary_field_instance')
->getIdMap()
->lookupDestinationIds([
4,
'article',
]));
$field_id = 'node.story.field_vocabulary_1_i_0_';
$field = FieldConfig::load($field_id);
$this
->assertFalse($field
->isRequired(), 'Field is not required');
$this
->assertTrue($field
->isTranslatable());
$field_id = 'node.story.field_vocabulary_2_i_1_';
$field = FieldConfig::load($field_id);
$this
->assertFalse($field
->isRequired(), 'Field is not required');
$this
->assertFalse($field
->isTranslatable());
$field_id = 'node.story.field_vocabulary_3_i_2_';
$field = FieldConfig::load($field_id);
$this
->assertFalse($field
->isRequired(), 'Field is not required');
$this
->assertTrue($field
->isTranslatable());
$field_type = FieldConfig::load('node.sponsor.field_type');
$this
->assertInstanceOf(FieldConfig::class, $field_type);
$this
->assertTrue($field
->isTranslatable());
}
public function testSkipNonExistentNodeType() {
$this
->mockFailure('d6_node_type', [
'type' => 'story',
]);
$migration = $this
->getMigration('d6_vocabulary_field_instance');
$this
->executeMigration($migration);
$this
->assertNull($migration
->getIdMap()
->lookupDestinationIds([
'type' => 'story',
])[0][0]);
}
}