MigrateFieldWidgetSettingsTest.php 4.48 KB
Newer Older
1
2
<?php

3
namespace Drupal\Tests\field\Kernel\Migrate\d6;
4

5
use Drupal\Core\Entity\Entity\EntityFormDisplay;
6
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
7
8

/**
9
10
 * Migrate field widget settings.
 *
11
 * @group migrate_drupal_6
12
 */
13
class MigrateFieldWidgetSettingsTest extends MigrateDrupal6TestBase {
14

15
16
17
  /**
   * {@inheritdoc}
   */
18
  protected static $modules = ['menu_ui'];
19

20
21
22
  /**
   * {@inheritdoc}
   */
23
  protected function setUp(): void {
24
    parent::setUp();
25
    $this->migrateFields();
26
27
28
29
30
31
32
  }

  /**
   * Test that migrated view modes can be loaded using D8 API's.
   */
  public function testWidgetSettings() {
    // Test the config can be loaded.
33
    $form_display = EntityFormDisplay::load('node.story.default');
34
    $this->assertNotNull($form_display);
35
36
37

    // Text field.
    $component = $form_display->getComponent('field_test');
38
39
40
    $expected = ['weight' => 1, 'type' => 'text_textfield'];
    $expected['settings'] = ['size' => 60, 'placeholder' => ''];
    $expected['third_party_settings'] = [];
41
    $expected['region'] = 'content';
42
    $this->assertIdentical($expected, $component, 'Text field settings are correct.');
43
44
45
46

    // Integer field.
    $component = $form_display->getComponent('field_test_two');
    $expected['type'] = 'number';
47
    $expected['weight'] = 1;
48
    $expected['settings'] = ['placeholder' => ''];
49
    $this->assertIdentical($expected, $component);
50
51
52

    // Float field.
    $component = $form_display->getComponent('field_test_three');
53
    $expected['weight'] = 2;
54
    $this->assertIdentical($expected, $component);
55
56
57
58

    // Email field.
    $component = $form_display->getComponent('field_test_email');
    $expected['type'] = 'email_default';
59
    $expected['weight'] = 6;
60
    $expected['settings'] = ['placeholder' => '', 'size' => 60];
61
    $this->assertIdentical($expected, $component);
62
63
64

    // Link field.
    $component = $form_display->getComponent('field_test_link');
65
66
    $this->assertIdentical('link_default', $component['type']);
    $this->assertIdentical(7, $component['weight']);
67
    $this->assertEmpty(array_filter($component['settings']));
68
69
70
71

    // File field.
    $component = $form_display->getComponent('field_test_filefield');
    $expected['type'] = 'file_generic';
72
    $expected['weight'] = 8;
73
    $expected['settings'] = ['progress_indicator' => 'bar'];
74
    $this->assertIdentical($expected, $component);
75
76
77
78

    // Image field.
    $component = $form_display->getComponent('field_test_imagefield');
    $expected['type'] = 'image_image';
79
    $expected['weight'] = 9;
80
    $expected['settings'] = ['progress_indicator' => 'bar', 'preview_image_style' => 'thumbnail'];
81
    $this->assertIdentical($expected, $component);
82
83
84
85

    // Phone field.
    $component = $form_display->getComponent('field_test_phone');
    $expected['type'] = 'telephone_default';
86
    $expected['weight'] = 13;
87
    $expected['settings'] = ['placeholder' => ''];
88
    $this->assertIdentical($expected, $component);
89
90
91
92
93

    // Date fields.
    $component = $form_display->getComponent('field_test_date');
    $expected['type'] = 'datetime_default';
    $expected['weight'] = 10;
94
    $expected['settings'] = [];
95
    $this->assertIdentical($expected, $component);
96
97
98

    $component = $form_display->getComponent('field_test_datestamp');
    $expected['weight'] = 11;
99
    $this->assertIdentical($expected, $component);
100
101
102

    $component = $form_display->getComponent('field_test_datetime');
    $expected['weight'] = 12;
103
    $this->assertIdentical($expected, $component);
104

105
106
107
108
    /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
    $display_repository = \Drupal::service('entity_display.repository');

    $component = $display_repository->getFormDisplay('node', 'employee', 'default')
109
      ->getComponent('field_company');
110
    $this->assertIsArray($component);
111
    $this->assertSame('options_select', $component['type']);
112

113
    $component = $display_repository->getFormDisplay('node', 'employee', 'default')
114
      ->getComponent('field_company_2');
115
    $this->assertIsArray($component);
116
117
    $this->assertSame('options_buttons', $component['type']);

118
    $component = $display_repository->getFormDisplay('node', 'employee', 'default')
119
      ->getComponent('field_company_3');
120
    $this->assertIsArray($component);
121
122
    $this->assertSame('entity_reference_autocomplete_tags', $component['type']);

123
    $component = $display_repository->getFormDisplay('node', 'employee', 'default')
124
      ->getComponent('field_commander');
125
    $this->assertIsArray($component);
126
    $this->assertSame('options_select', $component['type']);
127
128
129
  }

}