function UserValidationTest::assertAllowedValuesViolation

Same name and namespace in other branches
  1. 9 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()
  3. 11.x core/modules/user/tests/src/Kernel/UserValidationTest.php \Drupal\Tests\user\Kernel\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/tests/src/Kernel/UserValidationTest.php
Runs entity validation checks.

File

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

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->assertEqual($violations[0]->getPropertyPath(), $field_name === 'langcode' ? "{$field_name}.0" : "{$field_name}.0.value");
    $this->assertEqual($violations[0]->getMessage(), t('The value you selected is not a valid choice.'));
}

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