public function FieldTypeTest::testFieldSettingsForm in Double Field 8.3
Same name and namespace in other branches
- 4.x tests/src/Functional/FieldTypeTest.php \Drupal\Tests\double_field\Functional\FieldTypeTest::testFieldSettingsForm()
Test field settings form.
File
- tests/
src/ Functional/ FieldTypeTest.php, line 354
Class
- FieldTypeTest
- A test for Double Field type.
Namespace
Drupal\Tests\double_field\FunctionalCode
public function testFieldSettingsForm() : void {
// -- Boolean and string.
$storage_settings['storage']['first']['type'] = 'boolean';
$storage_settings['storage']['second']['type'] = 'string';
$this
->saveFieldStorageSettings($storage_settings);
$this
->drupalGet($this->fieldAdminPath);
$this
->assertXpath('//details[@id = "edit-settings-first"]/summary[text() = "First subfield - Boolean"]');
$this
->assertXpath('//input[@name = "settings[first][label]"]');
$this
->assertXpath('//input[@name = "settings[first][required]" and @checked = "checked"]');
$this
->assertNoXpath('//input[@name = "settings[first][list]"]');
$this
->assertXpath('//input[@name = "settings[first][on_label]" and @value = "On"]');
$this
->assertXpath('//input[@name = "settings[first][off_label]" and @value = "Off"]');
$this
->assertXpath('//details[@id = "edit-settings-second"]/summary[text() = "Second subfield - Text"]');
$this
->assertXpath('//input[@name = "settings[second][label]"]');
$this
->assertXpath('//input[@name = "settings[second][required]" and @checked = "checked"]');
$this
->assertXpath('//input[@name = "settings[second][list]" and not(@checked)]');
$this
->assertXpath('//textarea[@name = "settings[second][allowed_values]"]');
// -- Text and email.
$storage_settings['storage']['first']['type'] = 'text';
$storage_settings['storage']['second']['type'] = 'email';
// SQLite database gets locked here by some reason.
usleep(2500);
$this
->saveFieldStorageSettings($storage_settings);
$this
->drupalGet($this->fieldAdminPath);
$this
->assertXpath('//details[@id = "edit-settings-first"]/summary[text() = "First subfield - Text (long)"]');
$this
->assertXpath('//input[@name = "settings[first][label]"]');
$this
->assertXpath('//input[@name = "settings[first][required]" and @checked = "checked"]');
$this
->assertNoXpath('//input[@name = "settings[first][list]"]');
$this
->assertNoXpath('//textarea[@name = "settings[first][allowed_values]"]');
$this
->assertXpath('//details[@id = "edit-settings-second"]/summary[text() = "Second subfield - Email"]');
$this
->assertXpath('//input[@name = "settings[second][label]"]');
$this
->assertXpath('//input[@name = "settings[second][required]" and @checked = "checked"]');
$this
->assertXpath('//input[@name = "settings[second][list]" and not(@checked)]');
$this
->assertXpath('//textarea[@name = "settings[second][allowed_values]"]');
// -- Telephone and URL.
$storage_settings['storage']['first']['type'] = 'telephone';
$storage_settings['storage']['second']['type'] = 'uri';
$this
->saveFieldStorageSettings($storage_settings);
$this
->drupalGet($this->fieldAdminPath);
$this
->assertXpath('//details[@id = "edit-settings-first"]/summary[text() = "First subfield - Telephone"]');
$this
->assertXpath('//input[@name = "settings[first][label]"]');
$this
->assertXpath('//input[@name = "settings[first][required]" and @checked = "checked"]');
$this
->assertXpath('//input[@name = "settings[first][list]" and not(@checked)]');
$this
->assertXpath('//textarea[@name = "settings[first][allowed_values]"]');
$this
->assertXpath('//details[@id = "edit-settings-second"]/summary[text() = "Second subfield - Url"]');
$this
->assertXpath('//input[@name = "settings[second][label]"]');
$this
->assertXpath('//input[@name = "settings[second][required]" and @checked = "checked"]');
$this
->assertXpath('//input[@name = "settings[second][list]" and not(@checked)]');
$this
->assertXpath('//textarea[@name = "settings[second][allowed_values]"]');
// -- Date and integer.
$storage_settings['storage']['first']['type'] = 'datetime_iso8601';
$storage_settings['storage']['second']['type'] = 'integer';
$this
->saveFieldStorageSettings($storage_settings);
$this
->drupalGet($this->fieldAdminPath);
$this
->assertXpath('//details[@id = "edit-settings-first"]/summary[text() = "First subfield - Date"]');
$this
->assertXpath('//input[@name = "settings[first][label]"]');
$this
->assertXpath('//input[@name = "settings[first][required]" and @checked = "checked"]');
$this
->assertXpath('//input[@name = "settings[first][list]" and not(@checked)]');
$this
->assertXpath('//textarea[@name = "settings[first][allowed_values]"]');
$this
->assertXpath('//details[@id = "edit-settings-second"]/summary[text() = "Second subfield - Integer"]');
$this
->assertXpath('//input[@name = "settings[second][label]"]');
$this
->assertXpath('//input[@name = "settings[second][required]" and @checked = "checked"]');
$this
->assertXpath('//input[@name = "settings[second][list]" and not(@checked)]');
$this
->assertXpath('//textarea[@name = "settings[second][allowed_values]"]');
$this
->assertXpath('//input[@name = "settings[second][min]" and @type = "number"]');
$this
->assertXpath('//input[@name = "settings[second][max]" and @type = "number"]');
// -- Float and decimal.
$storage_settings['storage']['first']['type'] = 'float';
$storage_settings['storage']['second']['type'] = 'numeric';
$this
->saveFieldStorageSettings($storage_settings);
$this
->drupalGet($this->fieldAdminPath);
$this
->assertXpath('//details[@id = "edit-settings-first"]/summary[text() = "First subfield - Float"]');
$this
->assertXpath('//input[@name = "settings[first][label]"]');
$this
->assertXpath('//input[@name = "settings[first][required]" and @checked = "checked"]');
$this
->assertXpath('//input[@name = "settings[first][list]" and not(@checked)]');
$this
->assertXpath('//textarea[@name = "settings[first][allowed_values]"]');
$this
->assertXpath('//input[@name = "settings[first][min]" and @type = "number"]');
$this
->assertXpath('//input[@name = "settings[first][max]" and @type = "number"]');
$this
->assertXpath('//details[@id = "edit-settings-second"]/summary[text() = "Second subfield - Decimal"]');
$this
->assertXpath('//input[@name = "settings[second][label]"]');
$this
->assertXpath('//input[@name = "settings[second][required]" and @checked = "checked"]');
$this
->assertXpath('//input[@name = "settings[second][list]" and not(@checked)]');
$this
->assertXpath('//textarea[@name = "settings[second][allowed_values]"]');
$this
->assertXpath('//input[@name = "settings[second][min]" and @type = "number"]');
$this
->assertXpath('//input[@name = "settings[second][max]" and @type = "number"]');
// Submit some example settings and check whether they are accepted.
$edit = [
'settings[first][label]' => 'First',
'settings[first][list]' => 1,
'settings[first][allowed_values]' => '123|Aaa',
'settings[second][label]' => 'Second',
'settings[second][min]' => 10,
'settings[second][max]' => 20,
];
$this
->drupalPostForm(NULL, $edit, 'Save settings');
$this
->drupalGet($this->fieldAdminPath);
$this
->assertXpath('//input[@name = "settings[first][label]" and @value = "First"]');
$this
->assertXpath('//input[@name = "settings[first][list]" and @checked = "checked"]');
$this
->assertXpath('//textarea[@name = "settings[first][allowed_values]" and text() = "123|Aaa"]');
$this
->assertXpath('//input[@name = "settings[second][label]" and @value = "Second"]');
$this
->assertXpath('//input[@name = "settings[second][min]" and @value = 10]');
$this
->assertXpath('//input[@name = "settings[second][max]" and @value = 20]');
}