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($display_id, $component_id) {
$component = EntityViewDisplay::load($display_id)
->getComponent($component_id);
$this
->assertNull($component);
}
public function testEntityDisplaySettings() {
$field_name = "field_test";
$expected = [
'label' => 'above',
'weight' => 1,
'type' => 'text_trimmed',
'settings' => [
'trim_length' => 600,
],
'third_party_settings' => [],
'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'] = [
'scale' => 2,
'decimal_separator' => '.',
'thousand_separator' => ',',
'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_style' => '',
'image_link' => '',
];
$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);
$defaults = [
'format_type' => 'fallback',
'timezone_override' => '',
];
$expected['weight'] = 10;
$expected['type'] = 'datetime_default';
$expected['settings'] = [
'format_type' => 'fallback',
] + $defaults;
$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'] = [
'format_type' => 'medium',
] + $defaults;
$component = $display
->getComponent('field_test_datestamp');
$this
->assertSame($expected, $component);
$expected['weight'] = 12;
$expected['settings'] = [
'format_type' => 'short',
] + $defaults;
$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']);
}
}