public function MultipleSelectsWidgetUiTest::testWidgetRequired in Multiple Selects 8
Test the widget with multiple values when required.
File
- tests/
src/ Functional/ MultipleSelectsWidgetUiTest.php, line 143
Class
- MultipleSelectsWidgetUiTest
- Tests the multiple select widget.
Namespace
Drupal\Tests\multiple_selects\FunctionalCode
public function testWidgetRequired() {
$field_config = FieldConfig::loadByName('node', 'page', 'field_tags');
$field_config
->setRequired(TRUE);
$field_config
->save();
$title = $this
->randomMachineName();
$this
->drupalGet('node/add/page');
$this
->submitForm([
'title[0][value]' => $title,
], 'Save');
// Since the field is required, the form should throw an error.
$this
->assertSession()
->pageTextContains('Tags field is required.');
$tag_1_key = array_rand($this->tags);
$tag_1 = $this->tags[$tag_1_key];
$this
->submitForm([
'title[0][value]' => $title,
'field_tags[0][target_id]' => $tag_1
->id(),
], 'Save');
$node = $this
->drupalGetNodeByTitle($title);
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm([
'title[0][value]' => $title,
'field_tags[0][target_id]' => $tag_1
->id(),
], 'Save');
// Check that the node was updated.
$this
->assertSession()
->pageTextContains("Page {$title} has been updated.");
}