function ContentEntityFormFieldValidationFilteringTest::testFieldWidgetsWithLimitedValidationErrors
Same name in other branches
- 9 core/tests/Drupal/FunctionalTests/Entity/ContentEntityFormFieldValidationFilteringTest.php \Drupal\FunctionalTests\Entity\ContentEntityFormFieldValidationFilteringTest::testFieldWidgetsWithLimitedValidationErrors()
- 8.9.x core/tests/Drupal/FunctionalTests/Entity/ContentEntityFormFieldValidationFilteringTest.php \Drupal\FunctionalTests\Entity\ContentEntityFormFieldValidationFilteringTest::testFieldWidgetsWithLimitedValidationErrors()
- 11.x core/tests/Drupal/FunctionalTests/Entity/ContentEntityFormFieldValidationFilteringTest.php \Drupal\FunctionalTests\Entity\ContentEntityFormFieldValidationFilteringTest::testFieldWidgetsWithLimitedValidationErrors()
Tests field widgets with #limit_validation_errors.
File
-
core/
tests/ Drupal/ FunctionalTests/ Entity/ ContentEntityFormFieldValidationFilteringTest.php, line 133
Class
- ContentEntityFormFieldValidationFilteringTest
- Tests field validation filtering on content entity forms.
Namespace
Drupal\FunctionalTests\EntityCode
public function testFieldWidgetsWithLimitedValidationErrors() : void {
$assert_session = $this->assertSession();
$this->drupalGet($this->entityTypeId . '/add');
// The 'Test multiple' field is the only multi-valued field in the form, so
// try to add a new item for it. This tests the '#limit_validation_errors'
// property set by \Drupal\Core\Field\WidgetBase::formMultipleElements().
$assert_session->elementsCount('css', 'div#edit-test-multiple-wrapper div.js-form-type-textfield input', 1);
$this->submitForm([], 'Add another item');
$assert_session->elementsCount('css', 'div#edit-test-multiple-wrapper div.js-form-type-textfield input', 2);
// Now try to upload a file. This tests the '#limit_validation_errors'
// property set by
// \Drupal\file\Plugin\Field\FieldWidget\FileWidget::process().
$text_file = current($this->getTestFiles('text'));
$edit = [
'files[test_file_0]' => \Drupal::service('file_system')->realpath($text_file->uri),
];
$assert_session->elementNotExists('css', 'input#edit-test-file-0-remove-button');
$this->submitForm($edit, 'Upload');
$assert_session->elementExists('css', 'input#edit-test-file-0-remove-button');
// Make the 'Test multiple' field required and check that adding another
// item does not throw a validation error.
$field_config = FieldConfig::loadByName($this->entityTypeId, $this->entityTypeId, $this->fieldNameMultiple);
$field_config->setRequired(TRUE);
$field_config->save();
$this->drupalGet($this->entityTypeId . '/add');
$this->submitForm([], 'Add another item');
$assert_session->pageTextNotContains('Test multiple (value 1) field is required.');
// Check that saving the form without entering any value for the required
// field still throws the proper validation errors.
$this->submitForm([], 'Save');
$assert_session->pageTextContains('Test single field is required.');
$assert_session->pageTextContains('Test multiple (value 1) field is required.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.