Mercurial > hg > isophonics-drupal-site
comparison core/modules/user/src/Tests/Views/AccessPermissionTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\user\Tests\Views; | |
4 | |
5 use Drupal\user\Plugin\views\access\Permission; | |
6 use Drupal\views\Plugin\views\display\DisplayPluginBase; | |
7 use Drupal\views\Views; | |
8 | |
9 /** | |
10 * Tests views perm access plugin. | |
11 * | |
12 * @group user | |
13 * @see \Drupal\user\Plugin\views\access\Permission | |
14 */ | |
15 class AccessPermissionTest extends AccessTestBase { | |
16 | |
17 /** | |
18 * Views used by this test. | |
19 * | |
20 * @var array | |
21 */ | |
22 public static $testViews = ['test_access_perm']; | |
23 | |
24 /** | |
25 * Tests perm access plugin. | |
26 */ | |
27 public function testAccessPerm() { | |
28 $view = Views::getView('test_access_perm'); | |
29 $view->setDisplay(); | |
30 | |
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')); | |
34 | |
35 $this->assertFalse($view->display_handler->access($this->webUser)); | |
36 $this->assertTrue($view->display_handler->access($this->normalUser)); | |
37 } | |
38 | |
39 /** | |
40 * Tests access on render caching. | |
41 */ | |
42 public function testRenderCaching() { | |
43 $view = Views::getView('test_access_perm'); | |
44 $display = &$view->storage->getDisplay('default'); | |
45 $display['display_options']['cache'] = [ | |
46 'type' => 'tag', | |
47 ]; | |
48 | |
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'); | |
53 | |
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, ''); | |
59 | |
60 // Then with access. | |
61 $build = DisplayPluginBase::buildBasicRenderable('test_access_perm', 'default'); | |
62 $account_switcher->switchTo($this->webUser); | |
63 $result = $renderer->renderPlain($build); | |
64 $this->assertEqual($result, ''); | |
65 } | |
66 | |
67 } |