You are here

protected function EntityHierarchyValidationTest::doTestViolations in Entity Reference Hierarchy 3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/EntityHierarchyValidationTest.php \Drupal\Tests\entity_hierarchy\Kernel\EntityHierarchyValidationTest::doTestViolations()

Tests violations.

Parameters

\Drupal\Core\Entity\EntityInterface $referencedEntity: Referenced entity.

1 call to EntityHierarchyValidationTest::doTestViolations()
EntityHierarchyValidationTest::testValidation in tests/src/Kernel/EntityHierarchyValidationTest.php
Tests validation.

File

tests/src/Kernel/EntityHierarchyValidationTest.php, line 42

Class

EntityHierarchyValidationTest
Defines a class for testing validation constraint.

Namespace

Drupal\Tests\entity_hierarchy\Kernel

Code

protected function doTestViolations(EntityInterface $referencedEntity) {
  $violations = $this->parent
    ->validate();
  $this
    ->assertCount(1, $violations);
  $violation = $violations[0];
  $this
    ->assertEquals(sprintf('This entity (entity_test: %s) cannot be referenced as it is either a child or the same entity.', $referencedEntity
    ->id()), strip_tags($violation
    ->getMessage()));
  $this
    ->assertEquals(self::FIELD_NAME . '.0.target_id', $violation
    ->getPropertyPath());
}