function FieldWidgetConstraintValidatorTest::testEntityLevelConstraintValidation

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/FieldWidgetConstraintValidatorTest.php \Drupal\KernelTests\Core\Entity\FieldWidgetConstraintValidatorTest::testEntityLevelConstraintValidation()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/FieldWidgetConstraintValidatorTest.php \Drupal\KernelTests\Core\Entity\FieldWidgetConstraintValidatorTest::testEntityLevelConstraintValidation()
  3. 11.x core/tests/Drupal/KernelTests/Core/Entity/FieldWidgetConstraintValidatorTest.php \Drupal\KernelTests\Core\Entity\FieldWidgetConstraintValidatorTest::testEntityLevelConstraintValidation()

Tests entity level constraint validation.

File

core/tests/Drupal/KernelTests/Core/Entity/FieldWidgetConstraintValidatorTest.php, line 155

Class

FieldWidgetConstraintValidatorTest
Tests validation constraints for FieldWidgetConstraintValidatorTest.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testEntityLevelConstraintValidation() : void {
    $entity = EntityTestCompositeConstraint::create([
        'name' => 'entity-level-violation',
    ]);
    $entity->save();
    $errors = $this->getErrorsForEntity($entity);
    $this->assertEquals('Entity level validation', $errors['']);
    $entity->name->value = 'entity-level-violation-with-path';
    $errors = $this->getErrorsForEntity($entity);
    $this->assertEquals('Entity level validation', $errors['test][form][element']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.