trait AssertPageCacheContextsAndTagsTrait (View source)

deprecated in drupal:8.?.? and is removed from drupal:9.0.0. Use \Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait instead.

Provides test assertions for testing page-level cache contexts & tags.

Can be used by test classes that extend \Drupal\simpletest\WebTestBase.

Methods

enablePageCaching()

Enables page caching.

string[]
getCacheHeaderValues(string $header_name)

Gets a specific header value as array.

assertCacheContext(string $expected_cache_context)

Asserts whether an expected cache context was present in the last response.

assertNoCacheContext(string $not_expected_cache_context)

Asserts that a cache context was not present in the last response.

assertPageCacheContextsAndTags(Url $url, array $expected_contexts, array $expected_tags)

Asserts page cache miss, then hit for the given URL; checks cache headers.

debugCacheTags(array $actual_tags, array $expected_tags)

Provides debug information for cache tags.

assertCacheTags(array $expected_tags, bool $include_default_tags = TRUE)

Ensures that some cache tags are present in the current response.

bool
assertCacheContexts(array $expected_contexts, string $message = NULL, bool $include_default_contexts = TRUE)

Ensures that some cache contexts are present in the current response.

assertCacheMaxAge(int $max_age)

Asserts the max age header.

Details

protected enablePageCaching()

Enables page caching.

protected string[] getCacheHeaderValues(string $header_name)

Gets a specific header value as array.

Parameters

string $header_name

The header name.

Return Value

string[]

The header value, potentially exploded by spaces.

protected assertCacheContext(string $expected_cache_context)

Asserts whether an expected cache context was present in the last response.

Parameters

string $expected_cache_context

The expected cache context.

protected assertNoCacheContext(string $not_expected_cache_context)

Asserts that a cache context was not present in the last response.

Parameters

string $not_expected_cache_context

The expected cache context.

protected assertPageCacheContextsAndTags(Url $url, array $expected_contexts, array $expected_tags)

Asserts page cache miss, then hit for the given URL; checks cache headers.

Parameters

Url $url

The URL to test.

array $expected_contexts

The expected cache contexts for the given URL.

array $expected_tags

The expected cache tags for the given URL.

protected debugCacheTags(array $actual_tags, array $expected_tags)

Provides debug information for cache tags.

Parameters

array $actual_tags

The actual cache tags.

array $expected_tags

The expected cache tags.

protected assertCacheTags(array $expected_tags, bool $include_default_tags = TRUE)

Ensures that some cache tags are present in the current response.

Parameters

array $expected_tags

The expected tags.

bool $include_default_tags

(optional) Whether the default cache tags should be included.

protected bool assertCacheContexts(array $expected_contexts, string $message = NULL, bool $include_default_contexts = TRUE)

Ensures that some cache contexts are present in the current response.

Parameters

array $expected_contexts

The expected cache contexts.

string $message

(optional) A verbose message to output.

bool $include_default_contexts

(optional) Whether the default contexts should automatically be included.

Return Value

bool

TRUE if the assertion succeeded, FALSE otherwise.

protected assertCacheMaxAge(int $max_age)

Asserts the max age header.

Parameters

int $max_age