function TypedDataDefinitionEntityBundleTest::testEntityBundleDefinitions

Same name in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/TypedData/TypedDataDefinitionEntityBundleTest.php \Drupal\KernelTests\Core\TypedData\TypedDataDefinitionEntityBundleTest::testEntityBundleDefinitions()

Tests that entity bundle definitions are derived correctly.

Throws

\Drupal\Core\Entity\EntityStorageException

File

core/tests/Drupal/KernelTests/Core/TypedData/TypedDataDefinitionEntityBundleTest.php, line 56

Class

TypedDataDefinitionEntityBundleTest
Tests data type metadata for entity bundles.

Namespace

Drupal\KernelTests\Core\TypedData

Code

public function testEntityBundleDefinitions() : void {
    // Start without any bundles and no bundle-specific data type.
    $dataTypes = array_keys($this->typedDataManager
        ->getDefinitions());
    $this->assertContains('entity:entity_test_with_bundle', $dataTypes);
    $this->assertNotContains('entity:entity_test_with_bundle:test', $dataTypes);
    // Add a bundle and make sure the bundle-specific data type is registered.
    $bundle = $this->entityTestBundleStorage
        ->create([
        'id' => 'test',
    ]);
    $bundle->save();
    $dataTypes = array_keys($this->typedDataManager
        ->getDefinitions());
    $this->assertContains('entity:entity_test_with_bundle', $dataTypes);
    $this->assertContains('entity:entity_test_with_bundle:test', $dataTypes);
    // Delete the bundle and make sure the bundle-specific data type is no
    // longer returned.
    $bundle->delete();
    $dataTypes = array_keys($this->typedDataManager
        ->getDefinitions());
    $this->assertContains('entity:entity_test_with_bundle', $dataTypes);
    $this->assertNotContains('entity:entity_test_with_bundle:test', $dataTypes);
}

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