function ViewStorageTest::displayTests

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/ViewStorageTest.php \Drupal\Tests\views\Kernel\ViewStorageTest::displayTests()
  2. 10 core/modules/views/tests/src/Kernel/ViewStorageTest.php \Drupal\Tests\views\Kernel\ViewStorageTest::displayTests()
  3. 11.x core/modules/views/tests/src/Kernel/ViewStorageTest.php \Drupal\Tests\views\Kernel\ViewStorageTest::displayTests()

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

1 call to ViewStorageTest::displayTests()
ViewStorageTest::testConfigurationEntityCRUD in core/modules/views/tests/src/Kernel/ViewStorageTest.php
Tests CRUD operations.

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->assertEqual($display[$new_id]['display_plugin'], 'page', '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']);
}

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