function ViewStorageTest::loadTests

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Kernel/ViewStorageTest.php \Drupal\Tests\views\Kernel\ViewStorageTest::loadTests()
  2. 8.9.x 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 81

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->assertNotNull($view->get($property), "Property: {$property} loaded onto View.");
  }
  // Check the displays have been loaded correctly from config display data.
  $expected_displays = [
    'default',
    'block_1',
    'page_1',
  ];
  $this->assertEquals($expected_displays, array_keys($view->get('display')), '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->assertEquals($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->assertSame($display[$orig_key], $value, "{$key} is identical to saved data");
    }
  }
  // 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.