public function NameWidgetTest::testFieldEntry in Name Field 8
The most basic test.
File
- tests/
src/ Functional/ NameWidgetTest.php, line 46
Class
- NameWidgetTest
- Various tests on creating a name widget on a node.
Namespace
Drupal\Tests\name\FunctionalCode
public function testFieldEntry() {
$this
->drupalLogin($this->adminUser);
$new_name_field = [
'label' => 'Test name',
'field_name' => 'name_test',
'new_storage_type' => 'name',
];
$this
->drupalPostForm('admin/structure/types/manage/page/fields/add-field', $new_name_field, t('Save and continue'));
$storage_settings = [];
$this
->drupalPostForm('admin/structure/types/manage/page/fields/node.page.field_name_test/storage', $storage_settings, t('Save field settings'));
$this
->resetAll();
// Set up a field of each label display and test it shows.
$field_settings = [
'settings[components][title]' => TRUE,
'settings[components][given]' => TRUE,
'settings[components][middle]' => TRUE,
'settings[components][family]' => TRUE,
'settings[components][generational]' => TRUE,
'settings[components][credentials]' => TRUE,
'settings[minimum_components][title]' => TRUE,
'settings[minimum_components][given]' => TRUE,
'settings[minimum_components][middle]' => TRUE,
'settings[minimum_components][family]' => TRUE,
'settings[minimum_components][generational]' => TRUE,
'settings[minimum_components][credentials]' => TRUE,
'settings[show_component_required_marker]' => TRUE,
'settings[labels][title]' => t('Title'),
'settings[labels][given]' => t('Given'),
'settings[labels][middle]' => t('Middle name(s)'),
'settings[labels][family]' => t('Family'),
'settings[labels][generational]' => t('Generational'),
'settings[labels][credentials]' => t('Credentials'),
'settings[title_display][title]' => 'title',
'settings[title_display][given]' => 'title',
'settings[title_display][middle]' => 'description',
'settings[title_display][family]' => 'placeholder',
'settings[title_display][generational]' => 'none',
'settings[title_display][credentials]' => 'placeholder',
'settings[field_type][title]' => 'select',
'settings[field_type][given]' => 'text',
'settings[field_type][middle]' => 'text',
'settings[field_type][family]' => 'text',
'settings[field_type][generational]' => 'autocomplete',
'settings[field_type][credentials]' => 'text',
'settings[max_length][title]' => 31,
'settings[max_length][given]' => 45,
'settings[max_length][middle]' => 127,
'settings[max_length][family]' => 63,
'settings[max_length][generational]' => 15,
'settings[max_length][credentials]' => 255,
'settings[size][title]' => 6,
'settings[size][given]' => 10,
'settings[size][middle]' => 20,
'settings[size][family]' => 25,
'settings[size][generational]' => 5,
'settings[size][credentials]' => 35,
'settings[credentials_inline]' => TRUE,
'settings[sort_options][title]' => TRUE,
'settings[sort_options][generational]' => FALSE,
'settings[title_options]' => "-- --\nMr.\nMrs.\nMiss\nMs.\nDr.\nProf.",
'settings[generational_options]' => "-- --\nJr.\nSr.\nI\nII\nIII\nIV\nV\nVI\nVII\nVIII\nIX\nX",
'settings[component_layout]' => 'default',
];
$this
->drupalPostForm('admin/structure/types/manage/page/fields/node.page.field_name_test', $field_settings, t('Save settings'));
$this
->drupalGet('node/add/page');
$this
->assertFieldByTypeAndName('select', 'field_name_test[0][title]');
$this
->assertFieldByTypeAndName('input', 'field_name_test[0][given]');
$this
->assertFieldByTypeAndName('input', 'field_name_test[0][middle]');
$this
->assertFieldByTypeAndName('input', 'field_name_test[0][family]');
$this
->assertFieldByTypeAndName('input', 'field_name_test[0][generational]');
$this
->assertFieldByTypeAndName('input', 'field_name_test[0][credentials]');
// Checks the existence and positioning of the components.
foreach (_name_component_keys() as $component) {
$this
->assertComponentSettings($component, $field_settings);
}
$this
->assertFieldSettings($field_settings);
// Test the language layouts.
$this
->verbose('Testing asian');
$field_settings['settings[component_layout]'] = 'asian';
$this
->drupalPostForm('admin/structure/types/manage/page/fields/node.page.field_name_test', $field_settings, t('Save settings'));
$this
->drupalGet('node/add/page');
$this
->assertFieldSettings($field_settings);
$this
->verbose('Testing eastern');
$field_settings['settings[component_layout]'] = 'eastern';
$this
->drupalPostForm('admin/structure/types/manage/page/fields/node.page.field_name_test', $field_settings, t('Save settings'));
$this
->drupalGet('node/add/page');
$this
->assertFieldSettings($field_settings);
$this
->verbose('Testing german');
$field_settings['settings[component_layout]'] = 'german';
$this
->drupalPostForm('admin/structure/types/manage/page/fields/node.page.field_name_test', $field_settings, t('Save settings'));
$this
->drupalGet('node/add/page');
$this
->assertFieldSettings($field_settings);
$this
->verbose('Testing show_component_required_marker unchecked.');
$field_settings = [
'settings[show_component_required_marker]' => FALSE,
'settings[component_layout]' => 'default',
] + $field_settings;
$this
->drupalPostForm('admin/structure/types/manage/page/fields/node.page.field_name_test', $field_settings, t('Save settings'));
$this
->drupalGet('node/add/page');
foreach (_name_component_keys() as $component) {
$this
->assertComponentSettings($component, $field_settings);
}
}