You are here

public function EntityBundleListenerTest::testOnBundleCreate in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Entity/EntityBundleListenerTest.php \Drupal\KernelTests\Core\Entity\EntityBundleListenerTest::testOnBundleCreate()

@covers ::onBundleCreate

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().

File

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

Class

EntityBundleListenerTest
@coversDefaultClass \Drupal\Core\Entity\EntityBundleListener

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testOnBundleCreate() {
  $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']);
}