You are here

protected function UserValidationTest::assertAllowedValuesViolation in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Kernel/UserValidationTest.php \Drupal\Tests\user\Kernel\UserValidationTest::assertAllowedValuesViolation()
  2. 10 core/modules/user/tests/src/Kernel/UserValidationTest.php \Drupal\Tests\user\Kernel\UserValidationTest::assertAllowedValuesViolation()

Verifies that an AllowedValues violation exists for the given field.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity object to validate.

string $field_name: The name of the field to verify.

1 call to UserValidationTest::assertAllowedValuesViolation()
UserValidationTest::testValidation in core/modules/user/tests/src/Kernel/UserValidationTest.php
Runs entity validation checks.

File

core/modules/user/tests/src/Kernel/UserValidationTest.php, line 218

Class

UserValidationTest
Verify that user validity checks behave as designed.

Namespace

Drupal\Tests\user\Kernel

Code

protected function assertAllowedValuesViolation(EntityInterface $entity, $field_name) {
  $violations = $entity
    ->validate();
  $this
    ->assertCount(1, $violations, "Allowed values violation for {$field_name} found.");
  $this
    ->assertEquals($field_name === 'langcode' ? "{$field_name}.0" : "{$field_name}.0.value", $violations[0]
    ->getPropertyPath());
  $this
    ->assertEquals('The value you selected is not a valid choice.', $violations[0]
    ->getMessage());
}