You are here

public function ViewsEntitySchemaSubscriberIntegrationTest::testRevisionDataTableRename in Drupal 8

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

Tests that renaming revision tables adapts the views.

File

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

Class

ViewsEntitySchemaSubscriberIntegrationTest
Tests \Drupal\views\EventSubscriber\ViewsEntitySchemaSubscriber

Namespace

Drupal\Tests\views\Kernel\EventSubscriber

Code

public function testRevisionDataTableRename() {
  $this
    ->updateEntityTypeToRevisionableAndTranslatable(TRUE);

  /** @var \Drupal\views\Entity\View $view */
  $entity_storage = $this->entityTypeManager
    ->getStorage('view');
  $view = $entity_storage
    ->load('test_view_entity_test_revision');
  $this
    ->assertEqual('entity_test_update_revision', $view
    ->get('base_table'));
  $display = $view
    ->getDisplay('default');
  $this
    ->assertEqual('entity_test_update_revision', $display['display_options']['fields']['id']['table']);
  $this
    ->assertEqual('entity_test_update_revision_data', $display['display_options']['fields']['name']['table']);
  $this
    ->renameRevisionDataTable();
  $this
    ->applyEntityUpdates('entity_test_update');

  /** @var \Drupal\views\Entity\View $view */
  $entity_storage = $this->entityTypeManager
    ->getStorage('view');
  $view = $entity_storage
    ->load('test_view_entity_test_revision');

  // Ensure the base table got renamed, so also the views fields.
  $this
    ->assertEqual('entity_test_update_revision', $view
    ->get('base_table'));
  $display = $view
    ->getDisplay('default');
  $this
    ->assertEqual('entity_test_update_revision', $display['display_options']['fields']['id']['table']);
  $this
    ->assertEqual('entity_test_update_revision_data_new', $display['display_options']['fields']['name']['table']);

  // Check that only the impacted views have been updated.
  $this
    ->assertUpdatedViews([
    'test_view_entity_test',
    'test_view_entity_test_revision',
  ]);
}