You are here

protected function ViewStorageTest::displayTests in Drupal 10

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

Tests adding, saving, and loading displays on configuration entities.

File

core/modules/views/tests/src/Kernel/ViewStorageTest.php, line 153

Class

ViewStorageTest
Tests the CRUD functionality for a view.

Namespace

Drupal\Tests\views\Kernel

Code

protected function displayTests() {

  // Check whether a display can be added and saved to a View.
  $view = View::load('test_view_storage_new');
  $new_id = $view
    ->addDisplay('page', 'Test', 'test');
  $display = $view
    ->get('display');

  // Ensure the right display_plugin is created/instantiated.
  $this
    ->assertEquals('page', $display[$new_id]['display_plugin'], 'New page display "test" uses the right display plugin.');
  $executable = $view
    ->getExecutable();
  $executable
    ->initDisplay();
  $this
    ->assertInstanceOf(Page::class, $executable->displayHandlers
    ->get($new_id));

  // To save this with a new ID, we should use createDuplicate().
  $view = $view
    ->createDuplicate();
  $view
    ->set('id', 'test_view_storage_new_new2');
  $view
    ->save();
  $values = $this
    ->config('views.view.test_view_storage_new_new2')
    ->get();

  // Verify that the display was saved by ensuring it contains an array of
  // values in the view data.
  $this
    ->assertIsArray($values['display']['test']);
}