public function WidgetTest::testWidgetSettingsForm in Double Field 8.3
Same name and namespace in other branches
- 4.x tests/src/FunctionalJavascript/WidgetTest.php \Drupal\Tests\double_field\FunctionalJavascript\WidgetTest::testWidgetSettingsForm()
Test callback.
File
- tests/
src/ FunctionalJavascript/ WidgetTest.php, line 232
Class
- WidgetTest
- A tests for Double Field widget.
Namespace
Drupal\Tests\double_field\FunctionalJavascriptCode
public function testWidgetSettingsForm() : void {
$page = $this
->getSession()
->getPage();
// -- Boolean and string.
$settings = [];
$settings['storage']['first']['type'] = 'boolean';
$settings['storage']['second']['type'] = 'string';
$settings['widget']['first']['type'] = 'boolean';
$settings['widget']['second']['type'] = 'textfield';
$settings['second']['label'] = 'Second';
$this
->createField($settings);
$this
->drupalGet($this->formDisplayAdminPath);
$this
->openSettingsForm();
$this
->assertXpath('//input[@type = "checkbox" and @name = "fields[{field_name}][settings_edit_form][settings][inline]"]');
$this
->assertXpath('//td//details[1]/summary[text() = "First subfield - Boolean"]');
$this
->assertXpath('//td//details[1]//select[@name = "fields[{field_name}][settings_edit_form][settings][first][type]"]/option[@value = "checkbox" and text() = "Checkbox" and @selected = "selected"]');
$this
->assertNoXpath('//select[@name = "fields[{field_name}][settings_edit_form][settings][first][label_display]"]');
$this
->assertXpath('//td//details[1]//input[@name = "fields[{field_name}][settings_edit_form][settings][first][label]" and @value = "Ok"]');
$this
->assertXpath('//td//details[1]//input[@name = "fields[{field_name}][settings_edit_form][settings][first][prefix]" and @value = ""]');
$this
->assertXpath('//td//details[1]//input[@name = "fields[{field_name}][settings_edit_form][settings][first][suffix]" and @value = ""]');
$this
->assertXpath('//td//details[2]/summary[text() = "Second subfield - Text"]');
$this
->assertXpath('//td//details[2]//select[@name = "fields[{field_name}][settings_edit_form][settings][second][type]"]/option[@value = "textfield" and text() = "Textfield" and @selected = "selected"]');
$this
->assertXpath('//td//details[2]//select[@name = "fields[{field_name}][settings_edit_form][settings][second][label_display]"]/option[@value = "block" and text() = "Block" and @selected = "selected"]');
$this
->assertXpath('//td//details[2]//input[@name = "fields[{field_name}][settings_edit_form][settings][second][size]" and @type = "number" and @value = "10"]');
$this
->assertXpath('//td//details[2]//input[@name = "fields[{field_name}][settings_edit_form][settings][second][prefix]" and @value = ""]');
$this
->assertXpath('//td//details[2]//input[@name = "fields[{field_name}][settings_edit_form][settings][second][suffix]" and @value = ""]');
$details_1 = $page
->find('xpath', '//details[1]');
$details_1
->click();
$details_1
->fillField($this->fieldPrefix . '[first][label]', 'Yes');
$details_1
->fillField($this->fieldPrefix . '[first][prefix]', 'pfx-1');
$details_1
->fillField($this->fieldPrefix . '[first][suffix]', 'sfx-1');
$details_2 = $page
->find('xpath', '//details[2]');
$details_2
->click();
$details_2
->selectFieldOption($this->fieldPrefix . '[second][type]', 'email');
$details_2
->selectFieldOption($this->fieldPrefix . '[second][label_display]', 'inline');
$details_2
->fillField($this->fieldPrefix . '[second][size]', 15);
$details_2
->fillField($this->fieldPrefix . '[second][prefix]', 'pfx-2');
$details_2
->fillField($this->fieldPrefix . '[second][suffix]', 'sfx-2');
$this
->submitSettingsForm();
$expected_summary = [
'<b>First subfield - boolean</b>',
'Widget: checkbox',
'Label: Yes',
'Prefix (deprecated): pfx-1',
'Suffix (deprecated): sfx-1',
'<b>Second subfield - text</b>',
'Widget: email',
'Label display: inline',
'Size: 15',
'Prefix (deprecated): pfx-2',
'Suffix (deprecated): sfx-2',
];
$this
->assertSettingsSummary($expected_summary);
// -- Text and integer.
$settings = [];
$settings['storage']['first']['type'] = 'text';
$settings['storage']['second']['type'] = 'integer';
$settings['widget']['first']['type'] = 'textfield';
$settings['widget']['second']['type'] = 'number';
$this
->createField($settings);
$this
->drupalGet($this->formDisplayAdminPath);
$this
->openSettingsForm();
$this
->assertXpath('//input[@type = "checkbox" and @name = "fields[{field_name}][settings_edit_form][settings][inline]"]');
$this
->assertXpath('//td//details[1]/summary[text() = "First subfield - Text (long)"]');
$this
->assertXpath('//td//details[1]//select[@name = "fields[{field_name}][settings_edit_form][settings][first][type]"]/option[@value = "textarea" and text() = "Text area" and @selected = "selected"]');
$this
->assertXpath('//td//details[1]//select[@name = "fields[{field_name}][settings_edit_form][settings][first][label_display]"]/option[@value = "block" and text() = "Block" and @selected = "selected"]');
$this
->assertXpath('//td//details[1]//input[@name = "fields[{field_name}][settings_edit_form][settings][first][placeholder]" and @value = ""]');
$this
->assertXpath('//td//details[1]//input[@name = "fields[{field_name}][settings_edit_form][settings][first][cols]" and @value = "10"]');
$this
->assertXpath('//td//details[1]//input[@name = "fields[{field_name}][settings_edit_form][settings][first][rows]" and @value = "5"]');
$this
->assertXpath('//td//details[1]//input[@name = "fields[{field_name}][settings_edit_form][settings][first][prefix]" and @value = ""]');
$this
->assertXpath('//td//details[1]//input[@name = "fields[{field_name}][settings_edit_form][settings][first][suffix]" and @value = ""]');
$this
->assertXpath('//td//details[2]/summary[text() = "Second subfield - Integer"]');
$this
->assertXpath('//td//details[2]//select[@name = "fields[{field_name}][settings_edit_form][settings][second][type]"]/option[@value = "number" and text() = "Number" and @selected = "selected"]');
$this
->assertXpath('//td//details[2]//select[@name = "fields[{field_name}][settings_edit_form][settings][second][label_display]"]/option[@value = "block" and text() = "Block" and @selected = "selected"]');
$this
->assertXpath('//td//details[2]//input[@name = "fields[{field_name}][settings_edit_form][settings][second][prefix]" and @value = ""]');
$this
->assertXpath('//td//details[2]//input[@name = "fields[{field_name}][settings_edit_form][settings][second][suffix]" and @value = ""]');
$details_1 = $page
->find('xpath', '//details[1]');
$details_1
->click();
$details_1
->fillField($this->fieldPrefix . '[first][placeholder]', 'Wine');
$details_1
->fillField($this->fieldPrefix . '[first][cols]', '18');
$details_1
->fillField($this->fieldPrefix . '[first][rows]', '12');
$details_1
->fillField($this->fieldPrefix . '[first][prefix]', 'pfx-1');
$details_1
->fillField($this->fieldPrefix . '[first][suffix]', 'sfx-1');
$details_2 = $page
->find('xpath', '//details[2]');
$details_2
->click();
$details_2
->fillField($this->fieldPrefix . '[second][prefix]', 'pfx-2');
$details_2
->fillField($this->fieldPrefix . '[second][suffix]', 'sfx-2');
$this
->submitSettingsForm();
$expected_summary = [
'<b>First subfield - text (long)</b>',
'Widget: textarea',
'Label display: block',
'Columns: 18',
'Rows: 12',
'Placeholder: Wine',
'Prefix (deprecated): pfx-1',
'Suffix (deprecated): sfx-1',
'<b>Second subfield - integer</b>',
'Widget: number',
'Label display: block',
'Prefix (deprecated): pfx-2',
'Suffix (deprecated): sfx-2',
];
$this
->assertSettingsSummary($expected_summary);
// -- Float and decimal.
$settings = [];
$settings['storage']['first']['type'] = 'float';
$settings['storage']['second']['type'] = 'numeric';
$settings['widget']['first']['type'] = 'number';
$settings['widget']['second']['type'] = 'number';
$this
->createField($settings);
$this
->drupalGet($this->formDisplayAdminPath);
$this
->openSettingsForm();
$this
->assertXpath('//input[@type = "checkbox" and @name = "fields[{field_name}][settings_edit_form][settings][inline]"]');
$this
->assertXpath('//td//details[1]//summary[text() = "First subfield - Float"]');
$this
->assertXpath('//td//details[1]//select[@name = "fields[{field_name}][settings_edit_form][settings][first][type]"]/option[@value = "number" and text() = "Number" and @selected = "selected"]');
$this
->assertXpath('//td//details[1]//select[@name = "fields[{field_name}][settings_edit_form][settings][first][label_display]"]/option[@value = "block" and text() = "Block" and @selected = "selected"]');
$this
->assertXpath('//td//details[1]//input[@name = "fields[{field_name}][settings_edit_form][settings][first][prefix]" and @value = ""]');
$this
->assertXpath('//td//details[1]//input[@name = "fields[{field_name}][settings_edit_form][settings][first][suffix]" and @value = ""]');
$this
->assertXpath('//td//details[2]/summary[text() = "Second subfield - Decimal"]');
$this
->assertXpath('//td//details[2]//select[@name = "fields[{field_name}][settings_edit_form][settings][second][type]"]/option[@value = "number" and text() = "Number" and @selected = "selected"]');
$this
->assertXpath('//td//details[2]//select[@name = "fields[{field_name}][settings_edit_form][settings][second][label_display]"]/option[@value = "block" and text() = "Block" and @selected = "selected"]');
$this
->assertXpath('//td//details[2]//input[@name = "fields[{field_name}][settings_edit_form][settings][second][prefix]" and @value = ""]');
$this
->assertXpath('//td//details[2]//input[@name = "fields[{field_name}][settings_edit_form][settings][second][suffix]" and @value = ""]');
$details_1 = $page
->find('xpath', '//details[1]');
$details_1
->click();
$details_1
->fillField($this->fieldPrefix . '[first][prefix]', 'pfx-1');
$details_1
->fillField($this->fieldPrefix . '[first][suffix]', 'sfx-1');
$details_2 = $page
->find('xpath', '//details[2]');
$details_2
->click();
$details_2
->fillField($this->fieldPrefix . '[second][prefix]', 'pfx-2');
$details_2
->fillField($this->fieldPrefix . '[second][suffix]', 'sfx-2');
$this
->submitSettingsForm();
$expected_summary = [
'<b>First subfield - float</b>',
'Widget: number',
'Label display: block',
'Prefix (deprecated): pfx-1',
'Suffix (deprecated): sfx-1',
'<b>Second subfield - decimal</b>',
'Widget: number',
'Label display: block',
'Prefix (deprecated): pfx-2',
'Suffix (deprecated): sfx-2',
];
$this
->assertSettingsSummary($expected_summary);
// -- Email and telephone.
$settings['storage']['first']['type'] = 'email';
$settings['storage']['second']['type'] = 'telephone';
$settings['widget']['first']['type'] = 'email';
$settings['widget']['second']['type'] = 'tel';
$this
->createField($settings);
$this
->drupalGet($this->formDisplayAdminPath);
$this
->openSettingsForm();
$this
->assertXpath('//input[@type = "checkbox" and @name = "fields[{field_name}][settings_edit_form][settings][inline]"]');
$this
->assertXpath('//td//details[1]/summary[text() = "First subfield - Email"]');
$this
->assertXpath('//td//details[1]//select[@name = "fields[{field_name}][settings_edit_form][settings][first][type]"]/option[@value = "email" and text() = "Email" and @selected = "selected"]');
$this
->assertXpath('//td//details[1]//select[@name = "fields[{field_name}][settings_edit_form][settings][first][label_display]"]/option[@value = "block" and text() = "Block" and @selected = "selected"]');
$this
->assertXpath('//td//details[1]//input[@name = "fields[{field_name}][settings_edit_form][settings][first][size]" and @value = "10"]');
$this
->assertXpath('//td//details[1]//input[@name = "fields[{field_name}][settings_edit_form][settings][first][placeholder]" and @value = ""]');
$this
->assertXpath('//td//details[1]//input[@name = "fields[{field_name}][settings_edit_form][settings][first][prefix]" and @value = ""]');
$this
->assertXpath('//td//details[1]//input[@name = "fields[{field_name}][settings_edit_form][settings][first][suffix]" and @value = ""]');
$this
->assertXpath('//td//details[2]/summary[text() = "Second subfield - Telephone"]');
$this
->assertXpath('//td//details[2]//select[@name = "fields[{field_name}][settings_edit_form][settings][second][type]"]/option[@value = "tel" and text() = "Telephone" and @selected = "selected"]');
$this
->assertXpath('//td//details[2]//select[@name = "fields[{field_name}][settings_edit_form][settings][second][label_display]"]/option[@value = "block" and text() = "Block" and @selected = "selected"]');
$this
->assertXpath('//td//details[2]//input[@name = "fields[{field_name}][settings_edit_form][settings][second][size]" and @value = "10"]');
$this
->assertXpath('//td//details[2]//input[@name = "fields[{field_name}][settings_edit_form][settings][second][placeholder]" and @value = ""]');
$this
->assertXpath('//td//details[2]//input[@name = "fields[{field_name}][settings_edit_form][settings][second][prefix]" and @value = ""]');
$this
->assertXpath('//td//details[2]//input[@name = "fields[{field_name}][settings_edit_form][settings][second][suffix]" and @value = ""]');
$details_1 = $page
->find('xpath', '//details[1]');
$details_1
->click();
$details_1
->fillField($this->fieldPrefix . '[first][size]', 25);
$details_1
->fillField($this->fieldPrefix . '[first][placeholder]', "White");
$details_1
->fillField($this->fieldPrefix . '[first][prefix]', 'pfx-1');
$details_1
->fillField($this->fieldPrefix . '[first][suffix]', 'sfx-1');
$details_2 = $page
->find('xpath', '//details[2]');
$details_2
->click();
$details_2
->fillField($this->fieldPrefix . '[second][size]', 15);
$details_2
->fillField($this->fieldPrefix . '[second][placeholder]', "Dark");
$details_2
->fillField($this->fieldPrefix . '[second][prefix]', 'pfx-2');
$details_2
->fillField($this->fieldPrefix . '[second][suffix]', 'sfx-2');
$this
->submitSettingsForm();
$expected_summary = [
'<b>First subfield - email</b>',
'Widget: email',
'Label display: block',
'Size: 25',
'Placeholder: White',
'Prefix (deprecated): pfx-1',
'Suffix (deprecated): sfx-1',
'<b>Second subfield - telephone</b>',
'Widget: tel',
'Label display: block',
'Size: 15',
'Placeholder: Dark',
'Prefix (deprecated): pfx-2',
'Suffix (deprecated): sfx-2',
];
$this
->assertSettingsSummary($expected_summary);
// -- URL and date.
$settings['storage']['first']['type'] = 'uri';
$settings['storage']['second']['type'] = 'datetime_iso8601';
$settings['widget']['first']['type'] = 'url';
$settings['widget']['second']['type'] = 'datetime';
$this
->createField($settings);
$this
->drupalGet($this->formDisplayAdminPath);
$this
->openSettingsForm();
$this
->assertXpath('//input[@type = "checkbox" and @name = "fields[{field_name}][settings_edit_form][settings][inline]"]');
$this
->assertXpath('//td//details[1]/summary[text() = "First subfield - Url"]');
$this
->assertXpath('//td//details[1]//select[@name = "fields[{field_name}][settings_edit_form][settings][first][type]"]/option[@value = "url" and text() = "Url" and @selected = "selected"]');
$this
->assertXpath('//td//details[1]//select[@name = "fields[{field_name}][settings_edit_form][settings][first][label_display]"]/option[@value = "block" and text() = "Block" and @selected = "selected"]');
$this
->assertXpath('//td//details[1]//input[@name = "fields[{field_name}][settings_edit_form][settings][first][size]" and @value = "10"]');
$this
->assertXpath('//td//details[1]//input[@name = "fields[{field_name}][settings_edit_form][settings][first][placeholder]" and @value = ""]');
$this
->assertXpath('//td//details[1]//input[@name = "fields[{field_name}][settings_edit_form][settings][first][prefix]" and @value = ""]');
$this
->assertXpath('//td//details[1]//input[@name = "fields[{field_name}][settings_edit_form][settings][first][suffix]" and @value = ""]');
$this
->assertXpath('//td//details[2]/summary[text() = "Second subfield - Date"]');
$this
->assertXpath('//td//details[2]//select[@name = "fields[{field_name}][settings_edit_form][settings][second][type]"]/option[@value = "datetime" and text() = "Date" and @selected = "selected"]');
$this
->assertNoXpath('//select[@name = "fields[{field_name}][settings_edit_form][settings][second][label_display]"]');
$this
->assertXpath('//td//details[2]//input[@name = "fields[{field_name}][settings_edit_form][settings][second][prefix]" and @value = ""]');
$this
->assertXpath('//td//details[2]//input[@name = "fields[{field_name}][settings_edit_form][settings][second][suffix]" and @value = ""]');
$details_1 = $page
->find('xpath', '//details[1]');
$details_1
->click();
$details_1
->fillField($this->fieldPrefix . '[first][size]', 25);
$details_1
->fillField($this->fieldPrefix . '[first][placeholder]', "Beer");
$details_1
->fillField($this->fieldPrefix . '[first][prefix]', 'pfx-1');
$details_1
->fillField($this->fieldPrefix . '[first][suffix]', 'sfx-1');
$details_2 = $page
->find('xpath', '//details[2]');
$details_2
->click();
$details_2
->fillField($this->fieldPrefix . '[second][prefix]', 'pfx-2');
$details_2
->fillField($this->fieldPrefix . '[second][suffix]', 'sfx-2');
$this
->submitSettingsForm();
$expected_summary = [
'<b>First subfield - url</b>',
'Widget: url',
'Label display: block',
'Size: 25',
'Placeholder: Beer',
'Prefix (deprecated): pfx-1',
'Suffix (deprecated): sfx-1',
'<b>Second subfield - date</b>',
'Widget: datetime',
'Prefix (deprecated): pfx-2',
'Suffix (deprecated): sfx-2',
];
$this
->assertSettingsSummary($expected_summary);
}