public function ViewsDisplayCachingTest::testDisplayCacheability in Search API 8
Tests whether the search display plugin for a new view is available.
@dataProvider displayCacheabilityProvider
Parameters
string $display_id: The tested Views display's ID.
string[] $expected_cache_tags: The expected cache tags for the executed view.
string[] $expected_cache_contexts: The expected cache contexts for the executed view.
int $expected_max_age: The expected max cache age for the executed view.
bool $expected_results_cache: TRUE if the results cache is expected to be populated after executing the view, FALSE otherwise.
File
- tests/
src/ Kernel/ Views/ ViewsDisplayCachingTest.php, line 122  
Class
- ViewsDisplayCachingTest
 - Tests the Search API caching plugins for Views.
 
Namespace
Drupal\Tests\search_api\Kernel\ViewsCode
public function testDisplayCacheability($display_id, array $expected_cache_tags, array $expected_cache_contexts, $expected_max_age, $expected_results_cache) {
  $view = $this
    ->getView('search_api_test_cache', $display_id);
  // Before the search is executed, the query should not be cached.
  $this
    ->assertViewsResultsCacheNotPopulated($view);
  // Execute the search and assert the cacheability metadata.
  $this
    ->assertViewsCacheability($view, $expected_cache_tags, $expected_cache_contexts, $expected_max_age);
  // AssertViewsCache() destroys the view, get a fresh copy to continue the
  // test.
  $view = $this
    ->getView('search_api_test_cache', $display_id);
  // The query has been executed. The query should now be cached if the test
  // case expects it.
  if ($expected_results_cache) {
    $this
      ->assertViewsResultsCachePopulated($view);
    // Trigger the event that would cause a cache invalidation for the plugin
    // under test. Now the query result should not be cached any more.
    $this
      ->triggerInvalidation($display_id);
  }
  $this
    ->assertViewsResultsCacheNotPopulated($view);
}