You are here

public function EntityTypeTest::testConstraintMethods in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php \Drupal\Tests\Core\Entity\EntityTypeTest::testConstraintMethods()
  2. 10 core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php \Drupal\Tests\Core\Entity\EntityTypeTest::testConstraintMethods()

Tests the constraint methods.

@covers ::getConstraints @covers ::setConstraints @covers ::addConstraint

File

core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php, line 468

Class

EntityTypeTest
@coversDefaultClass \Drupal\Core\Entity\EntityType @group Entity

Namespace

Drupal\Tests\Core\Entity

Code

public function testConstraintMethods() {
  $definition = [
    'constraints' => [
      'EntityChanged' => [],
    ],
  ];
  $entity_type = $this
    ->setUpEntityType($definition);
  $this
    ->assertEquals($definition['constraints'], $entity_type
    ->getConstraints());
  $entity_type
    ->addConstraint('Test');
  $this
    ->assertEquals($definition['constraints'] + [
    'Test' => NULL,
  ], $entity_type
    ->getConstraints());
  $entity_type
    ->setConstraints([]);
  $this
    ->assertEquals([], $entity_type
    ->getConstraints());
}