function 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(EntityTypeEvents::DELETE, $event);
  // 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());
}

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