You are here

protected function UserValidationTest::assertAllowedValuesViolation in Zircon Profile 8.0

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

Verifies that a 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/src/Tests/UserValidationTest.php
Runs entity validation checks.

File

core/modules/user/src/Tests/UserValidationTest.php, line 213
Contains \Drupal\user\Tests\UserValidationTest.

Class

UserValidationTest
Verify that user validity checks behave as designed.

Namespace

Drupal\user\Tests

Code

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