function OptionsFieldUITest::testMachineNameSpecialCharacters

Same name and namespace in other branches
  1. 11.x core/modules/options/tests/src/FunctionalJavascript/OptionsFieldUITest.php \Drupal\Tests\options\FunctionalJavascript\OptionsFieldUITest::testMachineNameSpecialCharacters()

Tests `list_string` machine name with special characters.

File

core/modules/options/tests/src/FunctionalJavascript/OptionsFieldUITest.php, line 154

Class

OptionsFieldUITest
Tests the Options field UI functionality.

Namespace

Drupal\Tests\options\FunctionalJavascript

Code

public function testMachineNameSpecialCharacters() : void {
  $this->fieldName = 'field_options_text';
  $this->createOptionsField('list_string');
  $this->drupalGet($this->adminPath);
  $label_element_name = "field_storage[subform][settings][allowed_values][table][0][item][label]";
  $this->getSession()
    ->getPage()
    ->fillField($label_element_name, 'Hello world');
  $this->assertSession()
    ->assertWaitOnAjaxRequest();
  $this->exposeOptionMachineName(1);
  $key_element_name = "field_storage[subform][settings][allowed_values][table][0][item][key]";
  // Ensure that the machine name was generated correctly.
  $this->assertSession()
    ->fieldValueEquals($key_element_name, 'hello_world');
  // Ensure that the machine name can be overridden with a value that includes
  // special characters.
  $this->getSession()
    ->getPage()
    ->fillField($key_element_name, '.hello #world');
  $this->assertSession()
    ->assertWaitOnAjaxRequest();
  $this->getSession()
    ->getPage()
    ->pressButton('Save settings');
  $this->assertSession()
    ->statusMessageContains("Saved {$this->fieldName} configuration.");
  // Ensure that the machine name was saved correctly.
  $allowed_values = FieldStorageConfig::loadByName('node', $this->fieldName)
    ->getSetting('allowed_values');
  $this->assertSame([
    '.hello #world',
  ], array_keys($allowed_values));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.