You are here

public function WidgetTest::testWidgetSettingsForm in Double Field 4.x

Same name and namespace in other branches
  1. 8.3 tests/src/FunctionalJavascript/WidgetTest.php \Drupal\Tests\double_field\FunctionalJavascript\WidgetTest::testWidgetSettingsForm()

Test callback.

File

tests/src/FunctionalJavascript/WidgetTest.php, line 214

Class

WidgetTest
A tests for Double Field widget.

Namespace

Drupal\Tests\double_field\FunctionalJavascript

Code

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'] = 'checkbox';
  $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[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() = "Above" and @selected = "selected"]');
  $this
    ->assertXpath('//td//details[2]//input[@name = "fields[{field_name}][settings_edit_form][settings][second][size]" and @type = "number" and @value = "30"]');
  $details_1 = $page
    ->find('xpath', '//details[1]');
  $details_1
    ->click();
  $details_1
    ->fillField($this->fieldPrefix . '[first][label]', 'Yes');
  $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);
  $this
    ->submitSettingsForm();
  $expected_summary = [
    '<b>First subfield - boolean</b>',
    'Widget: checkbox',
    'Label: Yes',
    '<b>Second subfield - text</b>',
    'Widget: email',
    'Label display: inline',
    'Size: 15',
  ];
  $this
    ->assertSettingsSummary($expected_summary);

  // -- Text and integer.
  $settings = [];
  $settings['storage']['first']['type'] = 'text';
  $settings['storage']['second']['type'] = 'integer';
  $settings['widget']['first']['type'] = 'textarea';
  $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() = "Above" 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[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() = "Above" and @selected = "selected"]');
  $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');
  $this
    ->submitSettingsForm();
  $expected_summary = [
    '<b>First subfield - text (long)</b>',
    'Widget: textarea',
    'Label display: block',
    'Columns: 18',
    'Rows: 12',
    'Placeholder: Wine',
    '<b>Second subfield - integer</b>',
    'Widget: number',
    'Label display: block',
  ];
  $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() = "Above" and @selected = "selected"]');
  $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() = "Above" and @selected = "selected"]');
  $this
    ->submitSettingsForm();
  $expected_summary = [
    '<b>First subfield - float</b>',
    'Widget: number',
    'Label display: block',
    '<b>Second subfield - decimal</b>',
    'Widget: number',
    'Label display: block',
  ];
  $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() = "Above" and @selected = "selected"]');
  $this
    ->assertXpath('//td//details[1]//input[@name = "fields[{field_name}][settings_edit_form][settings][first][size]" and @value = "30"]');
  $this
    ->assertXpath('//td//details[1]//input[@name = "fields[{field_name}][settings_edit_form][settings][first][placeholder]" 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() = "Above" and @selected = "selected"]');
  $this
    ->assertXpath('//td//details[2]//input[@name = "fields[{field_name}][settings_edit_form][settings][second][size]" and @value = "30"]');
  $this
    ->assertXpath('//td//details[2]//input[@name = "fields[{field_name}][settings_edit_form][settings][second][placeholder]" 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_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");
  $this
    ->submitSettingsForm();
  $expected_summary = [
    '<b>First subfield - email</b>',
    'Widget: email',
    'Label display: block',
    'Size: 25',
    'Placeholder: White',
    '<b>Second subfield - telephone</b>',
    'Widget: tel',
    'Label display: block',
    'Size: 15',
    'Placeholder: Dark',
  ];
  $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() = "Above" and @selected = "selected"]');
  $this
    ->assertXpath('//td//details[1]//input[@name = "fields[{field_name}][settings_edit_form][settings][first][size]" and @value = "30"]');
  $this
    ->assertXpath('//td//details[1]//input[@name = "fields[{field_name}][settings_edit_form][settings][first][placeholder]" 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
    ->assertXpath('//td//details[2]//select[@name = "fields[{field_name}][settings_edit_form][settings][second][label_display]"]');
  $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_2 = $page
    ->find('xpath', '//details[2]');
  $details_2
    ->click();
  $this
    ->submitSettingsForm();
  $expected_summary = [
    '<b>First subfield - url</b>',
    'Widget: url',
    'Label display: block',
    'Size: 25',
    'Placeholder: Beer',
    '<b>Second subfield - date</b>',
    'Widget: datetime',
    'Label display: block',
  ];
  $this
    ->assertSettingsSummary($expected_summary);
}