function EntityBundleExistsConstraintValidatorTest::testInvalidEntityTypeId

Same name and namespace in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/Entity/EntityBundleExistsConstraintValidatorTest.php \Drupal\KernelTests\Core\Entity\EntityBundleExistsConstraintValidatorTest::testInvalidEntityTypeId()

Tests when the constraint's entityTypeId value is not valid.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityBundleExistsConstraintValidatorTest.php, line 134

Class

EntityBundleExistsConstraintValidatorTest
@group Entity @group Validation

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testInvalidEntityTypeId() : void {
    $entity_type_id = $this->randomMachineName();
    $definition = DataDefinition::create('string')->addConstraint('EntityBundleExists', $entity_type_id);
    $violations = $this->container
        ->get('typed_data_manager')
        ->create($definition, 'bar')
        ->validate();
    $this->assertCount(1, $violations);
    $this->assertSame("The 'bar' bundle does not exist on the '{$entity_type_id}' entity type.", (string) $violations->get(0)
        ->getMessage());
    $this->assertSame('', $violations->get(0)
        ->getPropertyPath());
}

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