You are here

public function FieldTypeTest::testFieldStorageSettingsForm in Double Field 4.x

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/FieldTypeTest.php \Drupal\Tests\double_field\Functional\FieldTypeTest::testFieldStorageSettingsForm()

Test field storage settings form.

File

tests/src/Functional/FieldTypeTest.php, line 137

Class

FieldTypeTest
A test for Double Field type.

Namespace

Drupal\Tests\double_field\Functional

Code

public function testFieldStorageSettingsForm() : void {
  $this
    ->drupalGet($this->fieldStorageAdminPath);
  foreach ([
    'first',
    'second',
  ] as $subfield) {
    $prefix = sprintf('//form//details[@id = "edit-settings-storage-%s"]', $subfield);
    $select_prefix = $prefix . "//select[@name = 'settings[storage][{$subfield}][type]' and count(option) = 10]";
    $this
      ->assertXpath($select_prefix . '/option[@value = "boolean" and text() = "Boolean"]');
    $this
      ->assertXpath($select_prefix . '/option[@value = "string" and text() = "Text"]');
    $this
      ->assertXpath($select_prefix . '/option[@value = "text" and text() = "Text (long)"]');
    $this
      ->assertXpath($select_prefix . '/option[@value = "integer" and text() = "Integer"]');
    $this
      ->assertXpath($select_prefix . '/option[@value = "float" and text() = "Float"]');
    $this
      ->assertXpath($select_prefix . '/option[@value = "numeric" and text() = "Decimal"]');
    $this
      ->assertXpath($select_prefix . '/option[@value = "email" and text() = "Email"]');
    $this
      ->assertXpath($select_prefix . '/option[@value = "telephone" and text() = "Telephone"]');
    $this
      ->assertXpath($select_prefix . '/option[@value = "datetime_iso8601" and text() = "Date"]');
    $this
      ->assertXpath($select_prefix . '/option[@value = "uri" and text() = "Url"]');
    $this
      ->assertXpath($prefix . "//input[@name = 'settings[storage][{$subfield}][maxlength]' and @value = 50]");
    $this
      ->assertXpath($prefix . "//input[@name = 'settings[storage][{$subfield}][precision]' and @value = 10]");
    $this
      ->assertXpath($prefix . "//input[@name = 'settings[storage][{$subfield}][scale]' and @value = 2]");
    $datetime_xpath = '//input[@value = "datetime"]/following-sibling::label[text() = "Date and time"]';
    $date_xpath = '//input[@value = "date"]/following-sibling::label[text() = "Date only"]';
    $this
      ->assertXpath(sprintf('//fieldset/legend[span[text() = "Date type"]]/following-sibling::div[%s and %s]', $datetime_xpath, $date_xpath));
  }

  // Submit some example settings and check if they are accepted.
  $edit = [
    'settings[storage][first][type]' => 'string',
    'settings[storage][first][maxlength]' => 15,
    'settings[storage][second][type]' => 'numeric',
    'settings[storage][second][precision]' => 30,
    'settings[storage][second][scale]' => 5,
  ];
  $this
    ->drupalGet($this->fieldStorageAdminPath);
  $this
    ->submitForm($edit, 'Save field settings');
  $message = new FormattableMarkup('Updated field %field_name field settings.', [
    '%field_name' => $this->fieldName,
  ]);
  $this
    ->assertStatusMessage($message);
  $this
    ->assertWarningMessage('Since storage type has been changed you need to verify the configuration of corresponding widget on form display page.');
  $this
    ->drupalGet($this->fieldStorageAdminPath);
  $this
    ->assertXpath('//select[@name = "settings[storage][first][type]"]/option[@selected = "selected" and @value = "string"]');
  $this
    ->assertXpath('//input[@name = "settings[storage][first][maxlength]" and @value = 15]');
  $this
    ->assertXpath('//select[@name = "settings[storage][second][type]"]/option[@selected = "selected" and @value = "numeric"]');
  $this
    ->assertXpath('//input[@name = "settings[storage][second][precision]" and @value = 30]');
  $this
    ->assertXpath('//input[@name = "settings[storage][second][scale]" and @value = 5]');
}