protected function UserValidationTest::assertLengthViolation in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/user/src/Tests/UserValidationTest.php \Drupal\user\Tests\UserValidationTest::assertLengthViolation()
Verifies that a length violation exists for the given field.
Parameters
\Drupal\core\Entity\EntityInterface $entity: The entity object to validate.
string $field_name: The field that violates the maximum length.
int $length: Number of characters that was exceeded.
int $count: (optional) The number of expected violations. Defaults to 1.
int $expected_index: (optional) The index at which to expect the violation. Defaults to 0.
1 call to UserValidationTest::assertLengthViolation()
- UserValidationTest::testValidation in core/
modules/ user/ src/ Tests/ UserValidationTest.php - Runs entity validation checks.
File
- core/
modules/ user/ src/ Tests/ UserValidationTest.php, line 197 - Contains \Drupal\user\Tests\UserValidationTest.
Class
- UserValidationTest
- Verify that user validity checks behave as designed.
Namespace
Drupal\user\TestsCode
protected function assertLengthViolation(EntityInterface $entity, $field_name, $length, $count = 1, $expected_index = 0) {
$violations = $entity
->validate();
$this
->assertEqual(count($violations), $count, "Violation found when {$field_name} is too long.");
$this
->assertEqual($violations[$expected_index]
->getPropertyPath(), "{$field_name}.0.value");
$field_label = $entity
->get($field_name)
->getFieldDefinition()
->getLabel();
$this
->assertEqual($violations[$expected_index]
->getMessage(), t('%name: may not be longer than @max characters.', array(
'%name' => $field_label,
'@max' => $length,
)));
}