function EntityBundleExistsConstraintValidatorTest::testEntityTypeIdFromMultipleParents

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

Tests getting the entity type ID from a deeply nested property path.

File

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

Class

EntityBundleExistsConstraintValidatorTest
@group Entity @group Validation

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testEntityTypeIdFromMultipleParents() : void {
    $tree_definition = MapDataDefinition::create()->setPropertyDefinition('info', MapDataDefinition::create()->setPropertyDefinition('entity_type_id', DataDefinition::create('string')))
        ->setPropertyDefinition('info2', MapDataDefinition::create()->setPropertyDefinition('bundle', DataDefinition::create('string')->addConstraint('EntityBundleExists', '%parent.%parent.info.entity_type_id')));
    $violations = $this->container
        ->get('typed_data_manager')
        ->create($tree_definition, [
        'info' => [
            'entity_type_id' => 'entity_test_with_bundle',
        ],
        'info2' => [
            'bundle' => 'bar',
        ],
    ])
        ->validate();
    $this->assertCount(1, $violations);
    $this->assertSame("The 'bar' bundle does not exist on the 'entity_test_with_bundle' entity type.", (string) $violations->get(0)
        ->getMessage());
    $this->assertSame('info2.bundle', $violations->get(0)
        ->getPropertyPath());
}

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