diff -u b/core/modules/system/src/Tests/Cache/CacheContextOptimizationTest.php b/core/modules/system/src/Tests/Cache/CacheContextOptimizationTest.php --- b/core/modules/system/src/Tests/Cache/CacheContextOptimizationTest.php +++ b/core/modules/system/src/Tests/Cache/CacheContextOptimizationTest.php @@ -81,11 +81,11 @@ } /** - * Ensures that 'user.roles' cache context is defining cacheable metadata. + * Ensures that 'user.roles' still works when it is optimized away. */ public function testUserRolesCacheContextOptimization() { - $user1 = $this->createUser(); - $this->assertEqual($user1->id(), 1); + $root_user = $this->createUser(); + $this->assertEqual($root_user->id(), 1); $authenticated_user = $this->createUser(['administer permissions']); $role = $authenticated_user->getRoles()[1]; @@ -110,10 +110,9 @@ $this->assertEqual($output, 'content for authenticated users'); // Even though the cache contexts have been optimized to only include 'user' - // cache context, the element should have been changed because - // 'user.roles' cache context defined a cacheable metadata for permission - // changes, which should have bubbled up for the element when it was - // optimized away. + // cache context, the element should have been changed because 'user.roles' + // cache context defined a cache tag for user entity changes23, which should + // have bubbled up for the element when it was optimized away. $authenticated_user->removeRole($role); $authenticated_user->save(); $element = $test_element; @@ -123,2 +122,3 @@ } + }