You are here

protected function CommentValidationTest::assertLengthViolation in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/comment/src/Tests/CommentValidationTest.php \Drupal\comment\Tests\CommentValidationTest::assertLengthViolation()

Verifies that a length violation exists for the given field.

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.

1 call to CommentValidationTest::assertLengthViolation()
CommentValidationTest::testValidation in core/modules/comment/src/Tests/CommentValidationTest.php
Tests the comment validation constraints.

File

core/modules/comment/src/Tests/CommentValidationTest.php, line 198
Contains \Drupal\comment\Tests\CommentValidationTest.

Class

CommentValidationTest
Tests comment validation constraints.

Namespace

Drupal\comment\Tests

Code

protected function assertLengthViolation(CommentInterface $comment, $field_name, $length) {
  $violations = $comment
    ->validate();
  $this
    ->assertEqual(count($violations), 1, "Violation found when {$field_name} is too long.");
  $this
    ->assertEqual($violations[0]
    ->getPropertyPath(), "{$field_name}.0.value");
  $field_label = $comment
    ->get($field_name)
    ->getFieldDefinition()
    ->getLabel();
  $this
    ->assertEqual($violations[0]
    ->getMessage(), t('%name: may not be longer than @max characters.', array(
    '%name' => $field_label,
    '@max' => $length,
  )));
}