public function FormTest::testFieldFormUnlimitedRequired in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/field/src/Tests/FormTest.php \Drupal\field\Tests\FormTest::testFieldFormUnlimitedRequired()
Tests the position of the required label.
File
- core/
modules/ field/ src/ Tests/ FormTest.php, line 332 - Contains \Drupal\field\Tests\FormTest.
Class
- FormTest
- Tests field form handling.
Namespace
Drupal\field\TestsCode
public function testFieldFormUnlimitedRequired() {
$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();
entity_get_form_display($this->field['entity_type'], $this->field['bundle'], 'default')
->setComponent($field_name)
->save();
// Display creation form -> 1 widget.
$this
->drupalGet('entity_test/add');
// Check that the Required symbol is present for the multifield label.
$element = $this
->xpath('//h4[contains(@class, "label") and contains(@class, "js-form-required") and contains(text(), :value)]', array(
':value' => $this->field['label'],
));
$this
->assertTrue(isset($element[0]), 'Required symbol added field label.');
// Check that the label of the field input is visually hidden and contains
// the field title and an indication of the delta for a11y.
$element = $this
->xpath('//label[@for=:for and contains(@class, "js-form-required") and contains(text(), :value)]', array(
':for' => 'edit-field-unlimited-0-value',
':value' => $this->field['label'] . ' (value 1)',
));
$this
->assertTrue(isset($element[0]), 'Required symbol not added for field input.');
}