示例#1
0
 /**
  * Verifies that a length violation exists for the given field.
  *
  * @param \Drupal\comment\CommentInterface $comment
  *   The comment object to validate.
  * @param string $field_name
  *   The field that violates the maximum length.
  * @param int $length
  *   Number of characters that was exceeded.
  */
 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)));
 }