protected function UserValidationTest::assertAllowedValuesViolation in Drupal 10
Same name and namespace in other branches
- 8 core/modules/user/tests/src/Kernel/UserValidationTest.php \Drupal\Tests\user\Kernel\UserValidationTest::assertAllowedValuesViolation()
- 9 core/modules/user/tests/src/Kernel/UserValidationTest.php \Drupal\Tests\user\Kernel\UserValidationTest::assertAllowedValuesViolation()
Verifies that an AllowedValues violation exists for the given field.
@internal
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity object to validate.
string $field_name: The name of the field to verify.
File
- core/
modules/ user/ tests/ src/ Kernel/ UserValidationTest.php, line 222
Class
- UserValidationTest
- Verify that user validity checks behave as designed.
Namespace
Drupal\Tests\user\KernelCode
protected function assertAllowedValuesViolation(EntityInterface $entity, string $field_name) : void {
$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());
}