3 namespace Drupal\Tests\views\Functional\Plugin;
5 use Drupal\Tests\views\Functional\ViewTestBase;
6 use Drupal\views\Tests\ViewTestData;
7 use Drupal\views\Views;
10 * Tests pluggable access for views.
13 * @todo It probably make sense to split the test up by one for role/perm/none
14 * and the two generic ones.
16 class AccessTest extends ViewTestBase {
19 * Views used by this test.
23 public static $testViews = ['test_access_none', 'test_access_static', 'test_access_dynamic'];
30 public static $modules = ['node'];
33 * Web user for testing.
35 * @var \Drupal\user\UserInterface
40 * Normal user for testing.
42 * @var \Drupal\user\UserInterface
44 protected $normalUser;
46 protected function setUp($import_test_views = TRUE) {
47 parent::setUp($import_test_views);
49 $this->enableViewsTestModule();
51 ViewTestData::createTestViews(get_class($this), ['views_test_data']);
53 $this->webUser = $this->drupalCreateUser();
55 $normal_role = $this->drupalCreateRole([]);
56 $this->normalUser = $this->drupalCreateUser(['views_test_data test permission']);
57 $this->normalUser->addRole($normal_role);
58 // @todo when all the plugin information is cached make a reset function and
63 * Tests none access plugin.
65 public function testAccessNone() {
66 $view = Views::getView('test_access_none');
69 $this->assertTrue($view->display_handler->access($this->webUser));
70 $this->assertTrue($view->display_handler->access($this->normalUser));
74 * @todo Test abstract access plugin.
78 * Tests static access check.
80 * @see \Drupal\views_test\Plugin\views\access\StaticTest
82 public function testStaticAccessPlugin() {
83 $view = Views::getView('test_access_static');
86 $access_plugin = $view->display_handler->getPlugin('access');
88 $this->assertFalse($access_plugin->access($this->normalUser));
89 $this->drupalGet('test_access_static');
90 $this->assertResponse(403);
92 $display = &$view->storage->getDisplay('default');
93 $display['display_options']['access']['options']['access'] = TRUE;
94 $access_plugin->options['access'] = TRUE;
96 // Saving a view will cause the router to be rebuilt when the kernel
97 // termination event fires. Simulate that here.
98 $this->container->get('router.builder')->rebuildIfNeeded();
100 $this->assertTrue($access_plugin->access($this->normalUser));
102 $this->drupalGet('test_access_static');
103 $this->assertResponse(200);