EntityBundleListenerTest.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace Drupal\KernelTests\Core\Entity;
  3. /**
  4. * @coversDefaultClass \Drupal\Core\Entity\EntityBundleListener
  5. *
  6. * @group Entity
  7. */
  8. class EntityBundleListenerTest extends EntityKernelTestBase {
  9. /**
  10. * @covers ::onBundleCreate
  11. *
  12. * Note: Installing the entity_schema_test module will mask the bug this test
  13. * was written to cover, as the field map cache is cleared manually by
  14. * \Drupal\Core\Field\FieldDefinitionListener::onFieldDefinitionCreate().
  15. */
  16. public function testOnBundleCreate() {
  17. $field_map = $this->container->get('entity_field.manager')->getFieldMap();
  18. $expected = [
  19. 'entity_test' => 'entity_test',
  20. ];
  21. $this->assertEquals($expected, $field_map['entity_test']['id']['bundles']);
  22. entity_test_create_bundle('custom');
  23. $field_map = $this->container->get('entity_field.manager')->getFieldMap();
  24. $expected = [
  25. 'entity_test' => 'entity_test',
  26. 'custom' => 'custom',
  27. ];
  28. $this->assertSame($expected, $field_map['entity_test']['id']['bundles']);
  29. }
  30. }