public function AccessPermissionTest::testRenderCaching in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/user/src/Tests/Views/AccessPermissionTest.php \Drupal\user\Tests\Views\AccessPermissionTest::testRenderCaching()
Tests access on render caching.
File
- core/
modules/ user/ src/ Tests/ Views/ AccessPermissionTest.php, line 47 - Contains \Drupal\user\Tests\Views\AccessPermissionTest.
Class
- AccessPermissionTest
- Tests views perm access plugin.
Namespace
Drupal\user\Tests\ViewsCode
public function testRenderCaching() {
$view = Views::getView('test_access_perm');
$display =& $view->storage
->getDisplay('default');
$display['display_options']['cache'] = [
'type' => 'tag',
];
/** @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 without access.
$build = DisplayPluginBase::buildBasicRenderable('test_access_perm', 'default');
$account_switcher
->switchTo($this->normalUser);
$result = $renderer
->renderPlain($build);
$this
->assertNotEqual($result, '');
// Then with access.
$build = DisplayPluginBase::buildBasicRenderable('test_access_perm', 'default');
$account_switcher
->switchTo($this->webUser);
$result = $renderer
->renderPlain($build);
$this
->assertEqual($result, '');
}