View source
<?php
namespace Drupal\Tests\field\Kernel\Migrate\d6;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
class MigrateFieldFormatterSettingsTest extends MigrateDrupal6TestBase {
protected static $modules = [
'comment',
'menu_ui',
'node',
];
protected function setUp() : void {
parent::setUp();
$this
->installConfig([
'comment',
]);
$this
->executeMigration('d6_comment_type');
$this
->migrateFields();
}
protected function assertComponentNotExists(string $display_id, string $component_id) : void {
$component = EntityViewDisplay::load($display_id)
->getComponent($component_id);
$this
->assertNull($component);
}
public function testEntityDisplaySettings() {
$field_name = "field_test";
$expected = [
'type' => 'text_trimmed',
'label' => 'above',
'settings' => [
'trim_length' => 600,
],
'third_party_settings' => [],
'weight' => 1,
'region' => 'content',
];
$display = EntityViewDisplay::load('node.story.teaser');
$this
->assertSame($expected, $display
->getComponent($field_name));
$display = EntityViewDisplay::load('node.test_page.teaser');
$expected['weight'] = 35;
$this
->assertSame($expected, $display
->getComponent($field_name));
$display = EntityViewDisplay::load('node.story.rss');
$expected['weight'] = 1;
$this
->assertSame($expected, $display
->getComponent($field_name));
$expected['type'] = 'text_default';
$expected['settings'] = [];
$display = EntityViewDisplay::load('node.story.default');
$this
->assertSame($expected, $display
->getComponent($field_name));
$content = $display
->get('content');
$this
->assertTrue(isset($content['field_test']), 'Settings for field_test exist.');
$this
->assertTrue(isset($content['field_test_two']), "Settings for field_test_two exist.");
$this
->assertTrue(isset($content['field_test_exclude_unset']), "Settings for field_test_exclude_unset exist.");
$expected['weight'] = 1;
$expected['type'] = 'number_integer';
$expected['settings'] = [
'thousand_separator' => ',',
'prefix_suffix' => TRUE,
];
$component = $display
->getComponent('field_test_two');
$this
->assertSame($expected, $component);
$expected['weight'] = 2;
$expected['type'] = 'number_decimal';
$expected['settings'] = [
'thousand_separator' => ',',
'decimal_separator' => '.',
'scale' => 2,
'prefix_suffix' => TRUE,
];
$component = $display
->getComponent('field_test_three');
$this
->assertSame($expected, $component);
$expected['weight'] = 6;
$expected['type'] = 'email_mailto';
$expected['settings'] = [];
$component = $display
->getComponent('field_test_email');
$this
->assertSame($expected, $component);
$expected['weight'] = 7;
$expected['type'] = 'link';
$expected['settings'] = [
'trim_length' => 80,
'url_only' => TRUE,
'url_plain' => TRUE,
'rel' => '0',
'target' => '0',
];
$component = $display
->getComponent('field_test_link');
$this
->assertSame($expected, $component);
$expected['settings']['url_only'] = FALSE;
$expected['settings']['url_plain'] = FALSE;
$display = EntityViewDisplay::load('node.story.teaser');
$component = $display
->getComponent('field_test_link');
$this
->assertSame($expected, $component);
$expected['weight'] = 8;
$expected['type'] = 'file_default';
$expected['settings'] = [
'use_description_as_link_text' => TRUE,
];
$component = $display
->getComponent('field_test_filefield');
$this
->assertSame($expected, $component);
$display = EntityViewDisplay::load('node.story.default');
$expected['type'] = 'file_url_plain';
$expected['settings'] = [];
$component = $display
->getComponent('field_test_filefield');
$this
->assertSame($expected, $component);
$expected['weight'] = 9;
$expected['type'] = 'image';
$expected['settings'] = [
'image_link' => '',
'image_style' => '',
'image_loading' => [
'attribute' => 'lazy',
],
];
$component = $display
->getComponent('field_test_imagefield');
$this
->assertSame($expected, $component);
$display = EntityViewDisplay::load('node.story.teaser');
$expected['settings']['image_link'] = 'file';
$component = $display
->getComponent('field_test_imagefield');
$this
->assertSame($expected, $component);
$expected['weight'] = 13;
$expected['type'] = 'basic_string';
$expected['settings'] = [];
$component = $display
->getComponent('field_test_phone');
$this
->assertSame($expected, $component);
$expected['weight'] = 10;
$expected['type'] = 'datetime_default';
$expected['settings'] = [
'timezone_override' => '',
'format_type' => 'fallback',
];
$component = $display
->getComponent('field_test_date');
$this
->assertSame($expected, $component);
$display = EntityViewDisplay::load('node.story.default');
$expected['settings']['format_type'] = 'long';
$component = $display
->getComponent('field_test_date');
$this
->assertSame($expected, $component);
$expected['weight'] = 11;
$expected['settings']['format_type'] = 'fallback';
$component = $display
->getComponent('field_test_datestamp');
$this
->assertSame($expected, $component);
$display = EntityViewDisplay::load('node.story.teaser');
$expected['settings'] = [
'timezone_override' => '',
'format_type' => 'medium',
];
$component = $display
->getComponent('field_test_datestamp');
$this
->assertSame($expected, $component);
$expected['weight'] = 12;
$expected['settings'] = [
'timezone_override' => '',
'format_type' => 'short',
];
$component = $display
->getComponent('field_test_datetime');
$this
->assertSame($expected, $component);
$display = EntityViewDisplay::load('node.story.default');
$expected['settings']['format_type'] = 'fallback';
$component = $display
->getComponent('field_test_datetime');
$this
->assertSame($expected, $component);
$display = EntityViewDisplay::load('node.story.rss');
$expected['settings']['format_type'] = 'fallback';
$component = $display
->getComponent('field_test_datetime');
$this
->assertSame($expected, $component);
$this
->assertSame([
[
'node',
'story',
'teaser',
'field_test',
],
], $this
->getMigration('d6_field_formatter_settings')
->getIdMap()
->lookupDestinationIds([
'story',
'teaser',
'node',
'field_test',
]));
$this
->assertComponentNotExists('node.test_planet.teaser', 'field_test_text_single_checkbox');
$display = EntityViewDisplay::load('node.employee.default');
$component = $display
->getComponent('field_company');
$this
->assertIsArray($component);
$this
->assertSame('entity_reference_label', $component['type']);
$this
->assertTrue($component['settings']['link']);
$display = EntityViewDisplay::load('node.employee.teaser');
$component = $display
->getComponent('field_company');
$this
->assertIsArray($component);
$this
->assertSame('entity_reference_label', $component['type']);
$this
->assertFalse($component['settings']['link']);
$component = $display
->getComponent('field_commander');
$this
->assertIsArray($component);
$this
->assertSame('entity_reference_label', $component['type']);
$this
->assertTrue($component['settings']['link']);
$display = EntityViewDisplay::load('comment.comment_node_a_thirty_two_char.default');
$component = $display
->getComponent('comment_body');
$this
->assertIsArray($component);
$this
->assertSame('text_default', $component['type']);
}
}