You are here

protected function ViewsCacheabilityMetadataExportTest::assertViewCacheabilityMetadata in Search API 8

Checks that the given view has the expected cacheability metadata.

Parameters

array $expected_cacheability_metadata: An array of cacheability metadata that is expected to be present on the view.

\Drupal\views\ViewExecutable $view: The view.

1 call to ViewsCacheabilityMetadataExportTest::assertViewCacheabilityMetadata()
ViewsCacheabilityMetadataExportTest::testViewExport in tests/src/Kernel/Views/ViewsCacheabilityMetadataExportTest.php
Tests that an exported view contains the right cacheability metadata.

File

tests/src/Kernel/Views/ViewsCacheabilityMetadataExportTest.php, line 179

Class

ViewsCacheabilityMetadataExportTest
Tests that cacheability metadata is included when Views config is exported.

Namespace

Drupal\Tests\search_api\Kernel\Views

Code

protected function assertViewCacheabilityMetadata(array $expected_cacheability_metadata, ViewExecutable $view) {

  // Cacheability metadata is stored separately for each Views display since
  // depending on how the display is configured it might have different
  // caching needs. Ensure to check all displays.
  foreach (self::$testViewDisplayIds as $display_id) {
    $view
      ->setDisplay($display_id);
    $display = $view
      ->getDisplay();
    $actual_cacheability_metadata = $display
      ->getCacheMetadata();
    $this
      ->assertArrayEquals($expected_cacheability_metadata['contexts'], $actual_cacheability_metadata
      ->getCacheContexts());
    $this
      ->assertArrayEquals($expected_cacheability_metadata['tags'], $actual_cacheability_metadata
      ->getCacheTags());
    $this
      ->assertEquals($expected_cacheability_metadata['max-age'], $actual_cacheability_metadata
      ->getCacheMaxAge());
  }
}