function CKEditor5ValidationTestTrait::violationsToArray

Same name in other branches
  1. 11.x core/modules/ckeditor5/tests/src/Kernel/CKEditor5ValidationTestTrait.php \Drupal\Tests\ckeditor5\Kernel\CKEditor5ValidationTestTrait::violationsToArray()

Transforms a constraint violation list object to an assertable array.

Parameters

\Symfony\Component\Validator\ConstraintViolationListInterface $violations: Validation constraint violations.

Return value

array An array with property paths as keys and violation messages as values.

2 calls to CKEditor5ValidationTestTrait::violationsToArray()
CKEditor5ValidationTestTrait::validatePairToViolationsArray in core/modules/ckeditor5/tests/src/Kernel/CKEditor5ValidationTestTrait.php
Decorator for CKEditor5::validatePair() that returns an assertable array.
ValidatorsTest::test in core/modules/ckeditor5/tests/src/Kernel/ValidatorsTest.php
@covers \Drupal\ckeditor5\Plugin\Validation\Constraint\CKEditor5ElementConstraintValidator @covers \Drupal\ckeditor5\Plugin\Validation\Constraint\StyleSensibleElementConstraintValidator @covers…

File

core/modules/ckeditor5/tests/src/Kernel/CKEditor5ValidationTestTrait.php, line 46

Class

CKEditor5ValidationTestTrait
Defines a trait for testing CKEditor 5 validity.

Namespace

Drupal\Tests\ckeditor5\Kernel

Code

private static function violationsToArray(ConstraintViolationListInterface $violations) : array {
    $actual_violations = [];
    foreach ($violations as $violation) {
        if (!isset($actual_violations[$violation->getPropertyPath()])) {
            $actual_violations[$violation->getPropertyPath()] = (string) $violation->getMessage();
        }
        else {
            // Transform value from string to array.
            if (is_string($actual_violations[$violation->getPropertyPath()])) {
                $actual_violations[$violation->getPropertyPath()] = (array) $actual_violations[$violation->getPropertyPath()];
            }
            // And append.
            $actual_violations[$violation->getPropertyPath()][] = (string) $violation->getMessage();
        }
    }
    return $actual_violations;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.