X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fuser%2Ftests%2Fsrc%2FFunctional%2FViews%2FAccessPermissionTest.php;fp=web%2Fcore%2Fmodules%2Fuser%2Ftests%2Fsrc%2FFunctional%2FViews%2FAccessPermissionTest.php;h=dde139149a818743e698df9aa816914513d65e72;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hp=0000000000000000000000000000000000000000;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0;p=yaffs-website diff --git a/web/core/modules/user/tests/src/Functional/Views/AccessPermissionTest.php b/web/core/modules/user/tests/src/Functional/Views/AccessPermissionTest.php new file mode 100644 index 000000000..dde139149 --- /dev/null +++ b/web/core/modules/user/tests/src/Functional/Views/AccessPermissionTest.php @@ -0,0 +1,67 @@ +setDisplay(); + + $access_plugin = $view->display_handler->getPlugin('access'); + $this->assertTrue($access_plugin instanceof Permission, 'Make sure the right class got instantiated.'); + $this->assertEqual($access_plugin->pluginTitle(), t('Permission')); + + $this->assertFalse($view->display_handler->access($this->webUser)); + $this->assertTrue($view->display_handler->access($this->normalUser)); + } + + /** + * Tests access on render caching. + */ + 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, ''); + } + +}