X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fviews%2Ftests%2Fsrc%2FFunctional%2FPlugin%2FAccessTest.php;fp=web%2Fcore%2Fmodules%2Fviews%2Ftests%2Fsrc%2FFunctional%2FPlugin%2FAccessTest.php;h=41aa6ec53a7c5b25dff9c55dd3c696d6a940bb3d;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/views/tests/src/Functional/Plugin/AccessTest.php b/web/core/modules/views/tests/src/Functional/Plugin/AccessTest.php new file mode 100644 index 000000000..41aa6ec53 --- /dev/null +++ b/web/core/modules/views/tests/src/Functional/Plugin/AccessTest.php @@ -0,0 +1,106 @@ +enableViewsTestModule(); + + ViewTestData::createTestViews(get_class($this), ['views_test_data']); + + $this->webUser = $this->drupalCreateUser(); + + $normal_role = $this->drupalCreateRole([]); + $this->normalUser = $this->drupalCreateUser(['views_test_data test permission']); + $this->normalUser->addRole($normal_role); + // @todo when all the plugin information is cached make a reset function and + // call it here. + } + + /** + * Tests none access plugin. + */ + public function testAccessNone() { + $view = Views::getView('test_access_none'); + $view->setDisplay(); + + $this->assertTrue($view->display_handler->access($this->webUser)); + $this->assertTrue($view->display_handler->access($this->normalUser)); + } + + /** + * @todo Test abstract access plugin. + */ + + /** + * Tests static access check. + * + * @see \Drupal\views_test\Plugin\views\access\StaticTest + */ + public function testStaticAccessPlugin() { + $view = Views::getView('test_access_static'); + $view->setDisplay(); + + $access_plugin = $view->display_handler->getPlugin('access'); + + $this->assertFalse($access_plugin->access($this->normalUser)); + $this->drupalGet('test_access_static'); + $this->assertResponse(403); + + $display = &$view->storage->getDisplay('default'); + $display['display_options']['access']['options']['access'] = TRUE; + $access_plugin->options['access'] = TRUE; + $view->save(); + // Saving a view will cause the router to be rebuilt when the kernel + // termination event fires. Simulate that here. + $this->container->get('router.builder')->rebuildIfNeeded(); + + $this->assertTrue($access_plugin->access($this->normalUser)); + + $this->drupalGet('test_access_static'); + $this->assertResponse(200); + } + +}