You are here

public function ViewsEntitySchemaSubscriberIntegrationTest::testDeleteEntityType in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Kernel/EventSubscriber/ViewsEntitySchemaSubscriberIntegrationTest.php \Drupal\Tests\views\Kernel\EventSubscriber\ViewsEntitySchemaSubscriberIntegrationTest::testDeleteEntityType()
  2. 10 core/modules/views/tests/src/Kernel/EventSubscriber/ViewsEntitySchemaSubscriberIntegrationTest.php \Drupal\Tests\views\Kernel\EventSubscriber\ViewsEntitySchemaSubscriberIntegrationTest::testDeleteEntityType()

Tests that views are disabled when an entity type is deleted.

File

core/modules/views/tests/src/Kernel/EventSubscriber/ViewsEntitySchemaSubscriberIntegrationTest.php, line 95

Class

ViewsEntitySchemaSubscriberIntegrationTest
Tests \Drupal\views\EventSubscriber\ViewsEntitySchemaSubscriber.

Namespace

Drupal\Tests\views\Kernel\EventSubscriber

Code

public function testDeleteEntityType() {
  $entity_storage = $this->entityTypeManager
    ->getStorage('view');

  // Make the test entity type revisionable.
  $this
    ->updateEntityTypeToRevisionable(TRUE);
  $views = $entity_storage
    ->loadMultiple();

  // Ensure that all test views exists.
  $this
    ->assertTrue(isset($views['test_view_entity_test']));
  $this
    ->assertTrue(isset($views['test_view_entity_test_revision']));
  $this
    ->assertTrue(isset($views['test_view_entity_test_data']));
  $this
    ->assertTrue(isset($views['test_view_entity_test_additional_base_field']));
  $event = new EntityTypeEvent($this->entityTypeManager
    ->getDefinition('entity_test_update'));
  $this->eventDispatcher
    ->dispatch($event, EntityTypeEvents::DELETE);

  // We expect that views which use 'entity_test_update' as base tables are
  // disabled.
  $views = $entity_storage
    ->loadMultiple();

  // Ensure that all test views still exists after the deletion of the
  // entity type.
  $this
    ->assertTrue(isset($views['test_view_entity_test']));
  $this
    ->assertTrue(isset($views['test_view_entity_test_revision']));
  $this
    ->assertTrue(isset($views['test_view_entity_test_data']));
  $this
    ->assertTrue(isset($views['test_view_entity_test_additional_base_field']));

  // Ensure that they are all disabled.
  $this
    ->assertFalse($views['test_view_entity_test']
    ->status());
  $this
    ->assertFalse($views['test_view_entity_test_revision']
    ->status());
  $this
    ->assertFalse($views['test_view_entity_test_data']
    ->status());
  $this
    ->assertFalse($views['test_view_entity_test_additional_base_field']
    ->status());
}