function EntityTypeTest::testConstraintMethods

Tests the constraint methods.

@legacy-covers ::getConstraints @legacy-covers ::setConstraints @legacy-covers ::addConstraint

File

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

Class

EntityTypeTest
Tests Drupal\Core\Entity\EntityType.

Namespace

Drupal\Tests\Core\Entity

Code

public function testConstraintMethods() : void {
  $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());
}

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