You are here

public function FilterAPITest::assertFilterFormatViolation in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/filter/tests/src/Kernel/FilterAPITest.php \Drupal\Tests\filter\Kernel\FilterAPITest::assertFilterFormatViolation()
  2. 10 core/modules/filter/tests/src/Kernel/FilterAPITest.php \Drupal\Tests\filter\Kernel\FilterAPITest::assertFilterFormatViolation()

Checks if an expected violation exists in the given violations.

Parameters

\Symfony\Component\Validator\ConstraintViolationListInterface $violations: The violations to assert.

mixed $invalid_value: The expected invalid value.

1 call to FilterAPITest::assertFilterFormatViolation()
FilterAPITest::testTypedDataAPI in core/modules/filter/tests/src/Kernel/FilterAPITest.php
Tests the function of the typed data type.

File

core/modules/filter/tests/src/Kernel/FilterAPITest.php, line 436

Class

FilterAPITest
Tests the behavior of the API of the Filter module.

Namespace

Drupal\Tests\filter\Kernel

Code

public function assertFilterFormatViolation(ConstraintViolationListInterface $violations, $invalid_value) {
  $filter_format_violation_found = FALSE;
  foreach ($violations as $violation) {
    if ($violation
      ->getRoot() instanceof FilterFormatDataType && $violation
      ->getInvalidValue() === $invalid_value) {
      $filter_format_violation_found = TRUE;
      break;
    }
  }
  $this
    ->assertTrue($filter_format_violation_found, new FormattableMarkup('Validation violation for invalid value "%invalid_value" found', [
    '%invalid_value' => $invalid_value,
  ]));
}