public function HandlerTest::testAccess in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/views/src/Tests/Handler/HandlerTest.php \Drupal\views\Tests\Handler\HandlerTest::testAccess()
Tests access to a handler.
See also
views_test_data_handler_test_access_callback
File
- core/
modules/ views/ src/ Tests/ Handler/ HandlerTest.php, line 342 - Contains \Drupal\views\Tests\Handler\HandlerTest.
Class
- HandlerTest
- Tests abstract handler definitions.
Namespace
Drupal\views\Tests\HandlerCode
public function testAccess() {
$view = Views::getView('test_handler_test_access');
$views_data = $this
->viewsData();
$views_data = $views_data['views_test_data'];
// Enable access to callback only field and deny for callback + arguments.
$this
->config('views_test_data.tests')
->set('handler_access_callback', TRUE)
->save();
$this
->config('views_test_data.tests')
->set('handler_access_callback_argument', FALSE)
->save();
$view
->initDisplay();
$view
->initHandlers();
foreach ($views_data['access_callback'] as $type => $info) {
if (!in_array($type, array(
'title',
'help',
))) {
$this
->assertTrue($view->field['access_callback'] instanceof HandlerBase, 'Make sure the user got access to the access_callback field ');
$this
->assertFalse(isset($view->field['access_callback_arguments']), 'Make sure the user got no access to the access_callback_arguments field ');
}
}
// Enable access to the callback + argument handlers and deny for callback.
$this
->config('views_test_data.tests')
->set('handler_access_callback', FALSE)
->save();
$this
->config('views_test_data.tests')
->set('handler_access_callback_argument', TRUE)
->save();
$view
->destroy();
$view
->initDisplay();
$view
->initHandlers();
foreach ($views_data['access_callback'] as $type => $info) {
if (!in_array($type, array(
'title',
'help',
))) {
$this
->assertFalse(isset($view->field['access_callback']), 'Make sure the user got no access to the access_callback field ');
$this
->assertTrue($view->field['access_callback_arguments'] instanceof HandlerBase, 'Make sure the user got access to the access_callback_arguments field ');
}
}
}