View source
<?php
namespace Drupal\field\Tests\Migrate\d6;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\migrate\Entity\Migration;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
class MigrateFieldFormatterSettingsTest extends MigrateDrupal6TestBase {
protected function setUp() {
parent::setUp();
$this
->migrateFields();
}
public function testEntityDisplaySettings() {
$field_name = "field_test";
$expected = array(
'label' => 'above',
'weight' => 1,
'type' => 'text_trimmed',
'settings' => array(
'trim_length' => 600,
),
'third_party_settings' => array(),
);
$display = EntityViewDisplay::load('node.story.teaser');
$this
->assertIdentical($expected, $display
->getComponent($field_name));
$display = EntityViewDisplay::load('node.test_page.teaser');
$expected['weight'] = 35;
$this
->assertIdentical($expected, $display
->getComponent($field_name));
$display = EntityViewDisplay::load('node.story.rss');
$expected['weight'] = 1;
$this
->assertIdentical($expected, $display
->getComponent($field_name));
$expected['type'] = 'text_default';
$expected['settings'] = array();
$display = EntityViewDisplay::load('node.story.default');
$this
->assertIdentical($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'] = array(
'thousand_separator' => ',',
'prefix_suffix' => TRUE,
);
$component = $display
->getComponent('field_test_two');
$this
->assertIdentical($expected, $component);
$expected['weight'] = 2;
$expected['type'] = 'number_decimal';
$expected['settings'] = array(
'scale' => 2,
'decimal_separator' => '.',
'thousand_separator' => ',',
'prefix_suffix' => TRUE,
);
$component = $display
->getComponent('field_test_three');
$this
->assertIdentical($expected, $component);
$expected['weight'] = 6;
$expected['type'] = 'email_mailto';
$expected['settings'] = array();
$component = $display
->getComponent('field_test_email');
$this
->assertIdentical($expected, $component);
$expected['weight'] = 7;
$expected['type'] = 'link';
$expected['settings'] = array(
'trim_length' => 80,
'url_only' => TRUE,
'url_plain' => TRUE,
'rel' => '0',
'target' => '0',
);
$component = $display
->getComponent('field_test_link');
$this
->assertIdentical($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
->assertIdentical($expected, $component);
$expected['weight'] = 8;
$expected['type'] = 'file_default';
$expected['settings'] = array();
$component = $display
->getComponent('field_test_filefield');
$this
->assertIdentical($expected, $component);
$display = EntityViewDisplay::load('node.story.default');
$expected['type'] = 'file_url_plain';
$component = $display
->getComponent('field_test_filefield');
$this
->assertIdentical($expected, $component);
$expected['weight'] = 9;
$expected['type'] = 'image';
$expected['settings'] = array(
'image_style' => '',
'image_link' => '',
);
$component = $display
->getComponent('field_test_imagefield');
$this
->assertIdentical($expected, $component);
$display = EntityViewDisplay::load('node.story.teaser');
$expected['settings']['image_link'] = 'file';
$component = $display
->getComponent('field_test_imagefield');
$this
->assertIdentical($expected, $component);
$expected['weight'] = 13;
$expected['type'] = 'basic_string';
$expected['settings'] = array();
$component = $display
->getComponent('field_test_phone');
$this
->assertIdentical($expected, $component);
$defaults = array(
'format_type' => 'fallback',
'timezone_override' => '',
);
$expected['weight'] = 10;
$expected['type'] = 'datetime_default';
$expected['settings'] = array(
'format_type' => 'fallback',
) + $defaults;
$component = $display
->getComponent('field_test_date');
$this
->assertIdentical($expected, $component);
$display = EntityViewDisplay::load('node.story.default');
$expected['settings']['format_type'] = 'long';
$component = $display
->getComponent('field_test_date');
$this
->assertIdentical($expected, $component);
$expected['weight'] = 11;
$expected['settings']['format_type'] = 'fallback';
$component = $display
->getComponent('field_test_datestamp');
$this
->assertIdentical($expected, $component);
$display = EntityViewDisplay::load('node.story.teaser');
$expected['settings'] = array(
'format_type' => 'medium',
) + $defaults;
$component = $display
->getComponent('field_test_datestamp');
$this
->assertIdentical($expected, $component);
$expected['weight'] = 12;
$expected['settings'] = array(
'format_type' => 'short',
) + $defaults;
$component = $display
->getComponent('field_test_datetime');
$this
->assertIdentical($expected, $component);
$display = EntityViewDisplay::load('node.story.default');
$expected['settings']['format_type'] = 'fallback';
$component = $display
->getComponent('field_test_datetime');
$this
->assertIdentical($expected, $component);
$display = EntityViewDisplay::load('node.story.rss');
$expected['settings']['format_type'] = 'fallback';
$component = $display
->getComponent('field_test_datetime');
$this
->assertIdentical($expected, $component);
$this
->assertIdentical(array(
'node',
'story',
'teaser',
'field_test',
), Migration::load('d6_field_formatter_settings')
->getIdMap()
->lookupDestinationID(array(
'story',
'teaser',
'node',
'field_test',
)));
}
}