function ViewStorageTest::loadTests

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

Tests loading configuration entities.

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

File

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

Class

ViewStorageTest
Tests the CRUD functionality for a view.

Namespace

Drupal\Tests\views\Kernel

Code

protected function loadTests() {
    $view = View::load('test_view_storage');
    $data = $this->config('views.view.test_view_storage')
        ->get();
    // Confirm that an actual view object is loaded and that it returns all of
    // expected properties.
    $this->assertInstanceOf(View::class, $view);
    foreach ($this->configProperties as $property) {
        $this->assertTrue($view->get($property) !== NULL, new FormattableMarkup('Property: @property loaded onto View.', [
            '@property' => $property,
        ]));
    }
    // Check the displays have been loaded correctly from config display data.
    $expected_displays = [
        'default',
        'block_1',
        'page_1',
    ];
    $this->assertEqual(array_keys($view->get('display')), $expected_displays, 'The correct display names are present.');
    // Check each ViewDisplay object and confirm that it has the correct key and
    // property values.
    foreach ($view->get('display') as $key => $display) {
        $this->assertEqual($key, $display['id'], 'The display has the correct ID assigned.');
        // Get original display data and confirm that the display options array
        // exists.
        $original_options = $data['display'][$key];
        foreach ($original_options as $orig_key => $value) {
            $this->assertIdentical($display[$orig_key], $value, new FormattableMarkup('@key is identical to saved data', [
                '@key' => $key,
            ]));
        }
    }
    // Make sure that loaded default views get a UUID.
    $view = Views::getView('test_view_storage');
    $this->assertNotEmpty($view->storage
        ->uuid());
}

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