function AccessResultTest::testInheritCacheability
Same name in other branches
- 8.9.x core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\AccessResultTest::testInheritCacheability()
- 10 core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\AccessResultTest::testInheritCacheability()
- 11.x core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\AccessResultTest::testInheritCacheability()
@covers ::inheritCacheability
File
-
core/
tests/ Drupal/ Tests/ Core/ Access/ AccessResultTest.php, line 538
Class
- AccessResultTest
- @coversDefaultClass \Drupal\Core\Access\AccessResult @group Access
Namespace
Drupal\Tests\Core\AccessCode
public function testInheritCacheability() {
// andIf(); 1st has defaults, 2nd has custom tags, contexts and max-age.
$access = AccessResult::allowed();
$other = AccessResult::allowed()->setCacheMaxAge(1500)
->cachePerPermissions()
->addCacheTags([
'node:20011988',
]);
$this->assertInstanceOf(AccessResult::class, $access->inheritCacheability($other));
$this->assertSame([
'user.permissions',
], $access->getCacheContexts());
$this->assertSame([
'node:20011988',
], $access->getCacheTags());
$this->assertSame(1500, $access->getCacheMaxAge());
// andIf(); 1st has custom tags, max-age, 2nd has custom contexts and max-age.
$access = AccessResult::allowed()->cachePerUser()
->setCacheMaxAge(43200);
$other = AccessResult::forbidden()->addCacheTags([
'node:14031991',
])
->setCacheMaxAge(86400);
$this->assertInstanceOf(AccessResult::class, $access->inheritCacheability($other));
$this->assertSame([
'user',
], $access->getCacheContexts());
$this->assertSame([
'node:14031991',
], $access->getCacheTags());
$this->assertSame(43200, $access->getCacheMaxAge());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.