protected function CommentValidationTest::assertLengthViolation in Drupal 10
Same name and namespace in other branches
- 8 core/modules/comment/tests/src/Kernel/CommentValidationTest.php \Drupal\Tests\comment\Kernel\CommentValidationTest::assertLengthViolation()
- 9 core/modules/comment/tests/src/Kernel/CommentValidationTest.php \Drupal\Tests\comment\Kernel\CommentValidationTest::assertLengthViolation()
Verifies that a length violation exists for the given field.
@internal
Parameters
\Drupal\comment\CommentInterface $comment: The comment object to validate.
string $field_name: The field that violates the maximum length.
int $length: Number of characters that was exceeded.
File
- core/
modules/ comment/ tests/ src/ Kernel/ CommentValidationTest.php, line 195
Class
- CommentValidationTest
- Tests comment validation constraints.
Namespace
Drupal\Tests\comment\KernelCode
protected function assertLengthViolation(CommentInterface $comment, string $field_name, int $length) : void {
$violations = $comment
->validate();
$this
->assertCount(1, $violations, "Violation found when {$field_name} is too long.");
$this
->assertEquals("{$field_name}.0.value", $violations[0]
->getPropertyPath());
$field_label = $comment
->get($field_name)
->getFieldDefinition()
->getLabel();
$this
->assertEquals(t('%name: may not be longer than @max characters.', [
'%name' => $field_label,
'@max' => $length,
]), $violations[0]
->getMessage());
}