You are here

public function FieldWidgetConstraintValidatorTest::testEntityLevelConstraintValidation in Drupal 8

Same name and namespace in other branches
  1. 9 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 153

Class

FieldWidgetConstraintValidatorTest
Tests validation constraints for FieldWidgetConstraintValidatorTest.

Namespace

Drupal\KernelTests\Core\Entity

Code

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