You are here

public function ViewsEntitySchemaSubscriberIntegrationTest::testDeleteEntityType in Zircon Profile 8.0

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

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

File

core/modules/views/src/Tests/EventSubscriber/ViewsEntitySchemaSubscriberIntegrationTest.php, line 97
Contains \Drupal\views\Tests\EventSubscriber\ViewsEntitySchemaSubscriberIntegrationTest.

Class

ViewsEntitySchemaSubscriberIntegrationTest
Tests \Drupal\views\EventSubscriber\ViewsEntitySchemaSubscriber

Namespace

Drupal\views\Tests\EventSubscriber

Code

public function testDeleteEntityType() {
  $entity_storage = $this->entityManager
    ->getStorage('view');
  $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->entityManager
    ->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());
}