function LinksetControllerTestBase::assertDrupalResponseCacheability
Same name in other branches
- 10 core/modules/system/tests/src/Functional/Menu/LinksetControllerTestBase.php \Drupal\Tests\system\Functional\Menu\LinksetControllerTestBase::assertDrupalResponseCacheability()
Helper to assert a cacheable value matches an expectation.
Parameters
string|false $expect_cache: 'HIT', 'MISS', or FALSE. Asserts the value of the X-Drupal-Cache header. FALSE if the page cache is not applicable.
\Drupal\Core\Cache\CacheableDependencyInterface $expected_metadata: The expected cacheability metadata.
\GuzzleHttp\Psr7\Response $response: The response on which to assert cacheability.
3 calls to LinksetControllerTestBase::assertDrupalResponseCacheability()
- LinksetControllerTest::testAccess in core/
modules/ system/ tests/ src/ Functional/ Menu/ LinksetControllerTest.php - Test the access control functionality of the linkset endpoint.
- LinksetControllerTest::testCacheability in core/
modules/ system/ tests/ src/ Functional/ Menu/ LinksetControllerTest.php - Test the cacheability of the linkset endpoint.
- LinksetControllerTest::testUserAccountMenu in core/
modules/ system/ tests/ src/ Functional/ Menu/ LinksetControllerTest.php - Tests that the user account menu behaves as it should.
File
-
core/
modules/ system/ tests/ src/ Functional/ Menu/ LinksetControllerTestBase.php, line 96
Class
- LinksetControllerTestBase
- A base class for implementing LinksetController tests.
Namespace
Drupal\Tests\system\Functional\MenuCode
protected function assertDrupalResponseCacheability($expect_cache, CacheableDependencyInterface $expected_metadata, Response $response) {
$this->assertTrue(in_array($expect_cache, [
'HIT',
'MISS',
FALSE,
], TRUE), 'Cache is HIT, MISS, FALSE.');
$this->assertSame($expected_metadata->getCacheContexts(), explode(' ', $response->getHeaderLine('X-Drupal-Cache-Contexts')));
$this->assertSame($expected_metadata->getCacheTags(), explode(' ', $response->getHeaderLine('X-Drupal-Cache-Tags')));
$max_age_message = $expected_metadata->getCacheMaxAge();
if ($max_age_message === 0) {
$max_age_message = '0 (Uncacheable)';
}
elseif ($max_age_message === -1) {
$max_age_message = '-1 (Permanent)';
}
$this->assertSame($max_age_message, $response->getHeaderLine('X-Drupal-Cache-Max-Age'));
if ($expect_cache) {
$this->assertSame($expect_cache, $response->getHeaderLine('X-Drupal-Cache'));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.