You are here

public function EntityHierarchyValidationTest::testValidation 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::testValidation()

Tests validation.

File

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

Class

EntityHierarchyValidationTest
Defines a class for testing validation constraint.

Namespace

Drupal\Tests\entity_hierarchy\Kernel

Code

public function testValidation() {

  // Create root user.
  $this
    ->createUser();
  $child = $this
    ->createTestEntity($this->parent
    ->id());

  // Try and reference child.
  $this->parent->{self::FIELD_NAME}->target_id = $child
    ->id();
  $this
    ->doTestViolations($child);

  // Try and reference self.
  $this->parent->{self::FIELD_NAME}->target_id = $this->parent
    ->id();
  $this
    ->doTestViolations($this->parent);

  // Try and reference grandchild.
  $grandchild = $this
    ->createTestEntity($child
    ->id());
  $this->parent->{self::FIELD_NAME}->target_id = $grandchild
    ->id();
  $this
    ->doTestViolations($grandchild);
}