You are here

public function CacheabilityTest::testBlockCaching in Search API Saved Searches 8

Tests caching of the "Save search" block.

File

tests/src/Functional/CacheabilityTest.php, line 55

Class

CacheabilityTest
Tests that this module provides correct cache metadata.

Namespace

Drupal\Tests\search_api_saved_searches\Functional

Code

public function testBlockCaching() {
  $block_label = 'Save search test block label';
  $this
    ->drupalPlaceBlock('search_api_saved_searches', [
    'label' => $block_label,
    'type' => 'default',
  ]);

  // Visit a search page. Assert that the block is visible.
  $this
    ->drupalGet('search-api-test');
  $assert_session = $this
    ->assertSession();
  $assert_session
    ->pageTextContains($block_label);

  // Now visit a page without a search. The block should not be visible.
  $this
    ->drupalGet('user/1');
  $assert_session
    ->pageTextNotContains($block_label);

  // If we set caching metadata correctly, visiting the search page again
  // should, again, give us the block.
  $this
    ->drupalGet('search-api-test');
  $assert_session
    ->pageTextContains($block_label);
}