function EntityBundleListenerTest::testOnBundleCreate

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityBundleListenerTest.php \Drupal\KernelTests\Core\Entity\EntityBundleListenerTest::testOnBundleCreate()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityBundleListenerTest.php \Drupal\KernelTests\Core\Entity\EntityBundleListenerTest::testOnBundleCreate()
  3. 10 core/tests/Drupal/KernelTests/Core/Entity/EntityBundleListenerTest.php \Drupal\KernelTests\Core\Entity\EntityBundleListenerTest::testOnBundleCreate()

Test bundle creation.

Note: Installing the entity_schema_test module will mask the bug this test was written to cover, as the field map cache is cleared manually by \Drupal\Core\Field\FieldDefinitionListener::onFieldDefinitionCreate().

@covers ::onBundleCreate

File

core/tests/Drupal/KernelTests/Core/Entity/EntityBundleListenerTest.php, line 23

Class

EntityBundleListenerTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Entity%21EntityBundleListener.php/class/EntityBundleListener/11.x" title="Reacts to entity bundle CRUD on behalf of the Entity system." class="local">\Drupal\Core\Entity\EntityBundleListener</a>

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testOnBundleCreate() : void {
    $field_map = $this->container
        ->get('entity_field.manager')
        ->getFieldMap();
    $expected = [
        'entity_test' => 'entity_test',
    ];
    $this->assertEquals($expected, $field_map['entity_test']['id']['bundles']);
    entity_test_create_bundle('custom');
    $field_map = $this->container
        ->get('entity_field.manager')
        ->getFieldMap();
    $expected = [
        'entity_test' => 'entity_test',
        'custom' => 'custom',
    ];
    $this->assertSame($expected, $field_map['entity_test']['id']['bundles']);
}

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