$this->normalRole =>
$this->normalRole,
];
$view->
save();
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::
service('renderer'
);
/** @var \Drupal\Core\Session\AccountSwitcherInterface $account_switcher */
$account_switcher = \Drupal::
service('account_switcher'
);
// First access as user with access.
$build = DisplayPluginBase::
buildBasicRenderable('test_access_role', 'default'
);
$account_switcher->
switchTo($this->normalUser
);
$result =
$renderer->
renderPlain($build);
$this->
assertContains('user.roles',
$build['#cache'
]['contexts'
]);
$this->
assertEquals(['config:views.view.test_access_role'
],
$build['#cache'
]['tags'
]);
$this->
assertEquals(Cache::PERMANENT,
$build['#cache'
]['max-age'
]);
$this->
assertNotSame('',
$result);
// Then without access.
$build = DisplayPluginBase::
buildBasicRenderable('test_access_role', 'default'
);
$account_switcher->
switchTo($this->webUser
);
$result =
$renderer->
renderPlain($build);
// @todo Fix this in https://www.drupal.org/node/2551037,