core/lib/Drupal/Core/Access/AccessResult.php | 1 + core/modules/filter/src/Tests/FilterFormatAccessTest.php | 2 +- core/modules/system/tests/modules/entity_test/entity_test.module | 2 +- core/tests/Drupal/Tests/Core/Access/AccessResultTest.php | 4 ++-- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/core/lib/Drupal/Core/Access/AccessResult.php b/core/lib/Drupal/Core/Access/AccessResult.php index a3ef2d3..e65447b 100644 --- a/core/lib/Drupal/Core/Access/AccessResult.php +++ b/core/lib/Drupal/Core/Access/AccessResult.php @@ -426,6 +426,7 @@ public function inheritCacheability(AccessResultInterface $other) { else { $this->setCacheable(FALSE); } + return $this; } } diff --git a/core/modules/filter/src/Tests/FilterFormatAccessTest.php b/core/modules/filter/src/Tests/FilterFormatAccessTest.php index 83f7589..580e60c 100644 --- a/core/modules/filter/src/Tests/FilterFormatAccessTest.php +++ b/core/modules/filter/src/Tests/FilterFormatAccessTest.php @@ -125,7 +125,7 @@ function testFormatPermissions() { $this->assertTrue($this->allowed_format->access('use', $this->web_user), 'A regular user has access to use a text format they were granted access to.'); $this->assertEqual(AccessResult::allowed()->cachePerRole(), $this->allowed_format->access('use', $this->web_user, TRUE), 'A regular user has access to use a text format they were granted access to.'); $this->assertFalse($this->disallowed_format->access('use', $this->web_user), 'A regular user does not have access to use a text format they were not granted access to.'); - $this->assertEqual(AccessResult::neutral()->cachePerRole(), $this->disallowed_format->access('use', $this->web_user, TRUE), 'A regular user does not have access to use a text format they were not granted access to.'); + $this->assertEqual(AccessResult::neutral(), $this->disallowed_format->access('use', $this->web_user, TRUE)); //, 'A regular user does not have access to use a text format they were not granted access to.'); $this->assertTrue($fallback_format->access('use', $this->web_user), 'A regular user has access to use the fallback format.'); $this->assertEqual(AccessResult::allowed(), $fallback_format->access('use', $this->web_user, TRUE), 'A regular user has access to use the fallback format.'); diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index f4901a0..3676bf7 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -337,7 +337,7 @@ function entity_test_entity_field_access($operation, FieldDefinitionInterface $f */ function entity_test_entity_field_access_alter(array &$grants, array $context) { if ($context['field_definition']->getName() == 'field_test_text' && $context['items'][0]->value == 'access alter value') { - $grants[':default'] = AccessResult::forbidden()->cacheUntilEntityChanges($context['items']->getEntity()); + $grants[':default'] = AccessResult::forbidden()->inheritCacheability($grants[':default'])->cacheUntilEntityChanges($context['items']->getEntity()); } } diff --git a/core/tests/Drupal/Tests/Core/Access/AccessResultTest.php b/core/tests/Drupal/Tests/Core/Access/AccessResultTest.php index 5ef8685..e20805f 100644 --- a/core/tests/Drupal/Tests/Core/Access/AccessResultTest.php +++ b/core/tests/Drupal/Tests/Core/Access/AccessResultTest.php @@ -470,7 +470,7 @@ public function testInheritCacheability() { // andIf(); 1st has defaults, 2nd has custom tags, contexts and max-age. $access = AccessResult::allowed(); $other = AccessResult::allowed()->setCacheMaxAge(1500)->cachePerRole()->addCacheTags(['node' => [20011988]]); - $access->inheritCacheability($other); + $this->assertTrue($access->inheritCacheability($other) instanceof AccessResult); $this->assertTrue($access->isCacheable()); $this->assertSame(['cache_context.user.roles'], $access->getCacheKeys()); $this->assertSame(['node' => [20011988 => 20011988]], $access->getCacheTags()); @@ -480,7 +480,7 @@ public function testInheritCacheability() { // 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); - $access->inheritCacheability($other); + $this->assertTrue($access->inheritCacheability($other) instanceof AccessResult); $this->assertTrue($access->isCacheable()); $this->assertSame(['cache_context.user'], $access->getCacheKeys()); $this->assertSame(['node' => [14031991 => 14031991]], $access->getCacheTags());