You are here

protected function ViewStorageTest::loadTests 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::loadTests()
  2. 9 core/modules/views/tests/src/Kernel/ViewStorageTest.php \Drupal\Tests\views\Kernel\ViewStorageTest::loadTests()

Tests loading configuration entities.

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
      ->assertNotNull($view
      ->get($property), 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
    ->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, 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());
}