3 namespace Drupal\Tests\user\Functional\Views;
5 use Drupal\user\Plugin\views\access\Permission;
6 use Drupal\views\Plugin\views\display\DisplayPluginBase;
7 use Drupal\views\Views;
10 * Tests views perm access plugin.
13 * @see \Drupal\user\Plugin\views\access\Permission
15 class AccessPermissionTest extends AccessTestBase {
18 * Views used by this test.
22 public static $testViews = ['test_access_perm'];
25 * Tests perm access plugin.
27 public function testAccessPerm() {
28 $view = Views::getView('test_access_perm');
31 $access_plugin = $view->display_handler->getPlugin('access');
32 $this->assertTrue($access_plugin instanceof Permission, 'Make sure the right class got instantiated.');
33 $this->assertEqual($access_plugin->pluginTitle(), t('Permission'));
35 $this->assertFalse($view->display_handler->access($this->webUser));
36 $this->assertTrue($view->display_handler->access($this->normalUser));
40 * Tests access on render caching.
42 public function testRenderCaching() {
43 $view = Views::getView('test_access_perm');
44 $display = &$view->storage->getDisplay('default');
45 $display['display_options']['cache'] = [
49 /** @var \Drupal\Core\Render\RendererInterface $renderer */
50 $renderer = \Drupal::service('renderer');
51 /** @var \Drupal\Core\Session\AccountSwitcherInterface $account_switcher */
52 $account_switcher = \Drupal::service('account_switcher');
54 // First access as user without access.
55 $build = DisplayPluginBase::buildBasicRenderable('test_access_perm', 'default');
56 $account_switcher->switchTo($this->normalUser);
57 $result = $renderer->renderPlain($build);
58 $this->assertNotEqual($result, '');
61 $build = DisplayPluginBase::buildBasicRenderable('test_access_perm', 'default');
62 $account_switcher->switchTo($this->webUser);
63 $result = $renderer->renderPlain($build);
64 $this->assertEqual($result, '');