function OptionsFieldUITest::testDefaultValueOptions
Same name in other branches
- 10 core/modules/options/tests/src/FunctionalJavascript/OptionsFieldUITest.php \Drupal\Tests\options\FunctionalJavascript\OptionsFieldUITest::testDefaultValueOptions()
Tests that the allowed options are available to the default value widget.
File
-
core/
modules/ options/ tests/ src/ FunctionalJavascript/ OptionsFieldUITest.php, line 86
Class
- OptionsFieldUITest
- Tests the Options field UI functionality.
Namespace
Drupal\Tests\options\FunctionalJavascriptCode
public function testDefaultValueOptions() : void {
$page = $this->getSession()
->getPage();
$assert_session = $this->assertSession();
$bundle_path = 'admin/structure/types/manage/' . $this->type;
// Create a field of type list:string.
$this->fieldUIAddNewFieldJS($bundle_path, 'test_string_list', 'Test string list', 'list_string', FALSE);
$page->findField('field_storage[subform][settings][allowed_values][table][0][item][label]')
->setValue('first');
$assert_session->assertWaitOnAjaxRequest();
$page->findField('set_default_value')
->setValue(TRUE);
// Assert that the option added in the subform is available to the default
// value field.
$this->assertSession()
->optionExists('default_value_input[field_test_string_list]', 'first');
$page->pressButton('Add another item');
$this->assertNotNull($assert_session->waitForElement('css', "[name='field_storage[subform][settings][allowed_values][table][1][item][label]']"));
$page->findField('field_storage[subform][settings][allowed_values][table][1][item][label]')
->setValue('second');
$assert_session->assertWaitOnAjaxRequest();
$assert_session->optionExists('default_value_input[field_test_string_list]', 'second');
$page->selectFieldOption('default_value_input[field_test_string_list]', 'second');
$page->pressButton('Save settings');
$assert_session->pageTextContains('Saved Test string list configuration.');
// Create a field of type list:integer.
$this->fieldUIAddNewFieldJS($bundle_path, 'test_int_list', 'Test int list', 'list_integer', FALSE);
$page->findField('field_storage[subform][settings][allowed_values][table][0][item][label]')
->setValue('first');
$assert_session->assertWaitOnAjaxRequest();
// Assert that no validation is performed.
$assert_session->statusMessageNotContains('Value field is required.');
$page->findField('field_storage[subform][settings][allowed_values][table][0][item][key]')
->setValue(1);
$assert_session->assertWaitOnAjaxRequest();
$page->findField('set_default_value')
->setValue(TRUE);
// Assert that the option added in the subform is available to the default
// value field.
$this->assertSession()
->optionExists('default_value_input[field_test_int_list]', 'first');
$page->selectFieldOption('default_value_input[field_test_int_list]', 'first');
$page->pressButton('Save settings');
$assert_session->pageTextContains('Saved Test int list configuration.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.