function FormTest::testFieldFormUnlimitedRequired
Same name in other branches
- 9 core/modules/field/tests/src/Functional/FormTest.php \Drupal\Tests\field\Functional\FormTest::testFieldFormUnlimitedRequired()
- 8.9.x core/modules/field/tests/src/Functional/FormTest.php \Drupal\Tests\field\Functional\FormTest::testFieldFormUnlimitedRequired()
- 11.x core/modules/field/tests/src/Functional/FormTest.php \Drupal\Tests\field\Functional\FormTest::testFieldFormUnlimitedRequired()
Tests the position of the required label.
File
-
core/
modules/ field/ tests/ src/ Functional/ FormTest.php, line 348
Class
- FormTest
- Tests field form handling.
Namespace
Drupal\Tests\field\FunctionalCode
public function testFieldFormUnlimitedRequired() : void {
$field_name = $this->fieldStorageUnlimited['field_name'];
$this->field['field_name'] = $field_name;
$this->field['required'] = TRUE;
FieldStorageConfig::create($this->fieldStorageUnlimited)
->save();
FieldConfig::create($this->field)
->save();
\Drupal::service('entity_display.repository')->getFormDisplay($this->field['entity_type'], $this->field['bundle'])
->setComponent($field_name)
->save();
// Display creation form -> 1 widget.
$this->drupalGet('entity_test/add');
// Check that the Required symbol is present for the label of the field
// with unlimited cardinality.
$this->assertSession()
->elementAttributeContains('xpath', "//h4[contains(@class, 'label') and contains(text(), '{$this->field['label']}')]", 'class', 'js-form-required');
// Check that the label of the field input is visually hidden and contains
// the field title and an indication of the delta for a11y.
$this->assertSession()
->elementExists('xpath', "//label[@for='edit-field-unlimited-0-value' and contains(@class, 'visually-hidden') and contains(text(), '{$this->field['label']} (value 1)')]");
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.