// Verify that the render caching is working so that other tests can be
// trusted.
$element =
$test_element;
$element['#markup'
] = 'this should not be visible';
$output = \Drupal::
service('renderer'
)->
renderRoot($element);
$this->
assertEquals('content for authenticated users',
$output);
// 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 cache tag for user entity changes, which should
// have bubbled up for the element when it was optimized away.
$authenticated_user->
removeRole($role);
$authenticated_user->
save();
$element =
$test_element;
$element['#markup'
] = 'this should be visible';
$output = \Drupal::
service('renderer'
)->
renderRoot($element);
$this->
assertEquals('this should be visible',
$output);
}}