You are here

protected function ViewsCacheInvalidationTest::doAssertCached in Search API 8

Checks the cache status of the view for the given user.

Parameters

string $assert_method: The method to use for asserting that the view is cached or not cached.

int $user_key: The key of the user for which to perform the check.

2 calls to ViewsCacheInvalidationTest::doAssertCached()
ViewsCacheInvalidationTest::assertCached in tests/src/Kernel/Views/ViewsCacheInvalidationTest.php
Checks that the view is cached for the given user.
ViewsCacheInvalidationTest::assertNotCached in tests/src/Kernel/Views/ViewsCacheInvalidationTest.php
Checks that the view is not cached for the given user.

File

tests/src/Kernel/Views/ViewsCacheInvalidationTest.php, line 359

Class

ViewsCacheInvalidationTest
Tests that cached Search API views get invalidated at the right occasions.

Namespace

Drupal\Tests\search_api\Kernel\Views

Code

protected function doAssertCached($assert_method, $user_key) {

  // Ensure that any post request indexing is done. This is normally handled
  // at the end of the request but since we are running a KernelTest we are
  // not executing any requests and need to trigger this manually.
  $this
    ->triggerPostRequestIndexing();

  // Set the user that will be used to check the cache status.
  $this
    ->setCurrentUser($user_key);

  // Retrieve the cached data and perform the assertion.
  $view = $this
    ->getView();
  $view
    ->build();

  /** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache */
  $cache = $view
    ->getDisplay()
    ->getPlugin('cache');
  $cached_data = $cache
    ->cacheGet('results');
  $this
    ->{$assert_method}($cached_data);
}