You are here

public function ViewsEntitySchemaSubscriberIntegrationTest::testViewSaveException in Drupal 10

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

Tests the case when a view could not be updated automatically.

File

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

Class

ViewsEntitySchemaSubscriberIntegrationTest
Tests \Drupal\views\EventSubscriber\ViewsEntitySchemaSubscriber.

Namespace

Drupal\Tests\views\Kernel\EventSubscriber

Code

public function testViewSaveException() {
  $this
    ->renameBaseTable();
  \Drupal::state()
    ->set('entity_test_update.throw_view_exception', 'test_view_entity_test');
  $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');

  // Check that the table names were not updated automatically for the
  // 'test_view_entity_test' view.
  $this
    ->assertEquals('entity_test_update', $view
    ->get('base_table'));
  $display = $view
    ->getDisplay('default');
  $this
    ->assertEquals('entity_test_update', $display['display_options']['fields']['id']['table']);
  $this
    ->assertEquals('entity_test_update', $display['display_options']['fields']['name']['table']);

  // Check that the other two views impacted by the entity update were updated
  // automatically.
  $view = $entity_storage
    ->load('test_view_entity_test_data');
  $this
    ->assertEquals('entity_test_update_new', $view
    ->get('base_table'));
  $display = $view
    ->getDisplay('default');
  $this
    ->assertEquals('entity_test_update_new', $display['display_options']['fields']['id']['table']);
  $this
    ->assertEquals('entity_test_update_data', $display['display_options']['fields']['name']['table']);
  $view = $entity_storage
    ->load('test_view_entity_test_additional_base_field');
  $this
    ->assertEquals('entity_test_update_new', $view
    ->get('base_table'));
  $display = $view
    ->getDisplay('default');
  $this
    ->assertEquals('entity_test_update_new', $display['display_options']['fields']['id']['table']);
  $this
    ->assertEquals('entity_test_update_new', $display['display_options']['fields']['new_base_field']['table']);
  $this
    ->assertUpdatedViews([
    'test_view_entity_test_data',
    'test_view_entity_test_additional_base_field',
  ]);
}