function AreaTest::testAreaAccess
Same name in other branches
- 9 core/modules/views/tests/src/Functional/Handler/AreaTest.php \Drupal\Tests\views\Functional\Handler\AreaTest::testAreaAccess()
- 8.9.x core/modules/views/tests/src/Functional/Handler/AreaTest.php \Drupal\Tests\views\Functional\Handler\AreaTest::testAreaAccess()
- 11.x core/modules/views/tests/src/Kernel/Handler/AreaTest.php \Drupal\Tests\views\Kernel\Handler\AreaTest::testAreaAccess()
Tests the access for an area.
File
-
core/
modules/ views/ tests/ src/ Kernel/ Handler/ AreaTest.php, line 90
Class
- AreaTest
- Tests the plugin base of the area handler.
Namespace
Drupal\Tests\views\Kernel\HandlerCode
public function testAreaAccess() : void {
// Test with access denied for the area handler.
$view = Views::getView('test_example_area_access');
$view->initDisplay();
$view->initHandlers();
$handlers = $view->display_handler
->getHandlers('empty');
$this->assertCount(0, $handlers);
$output = $view->preview();
$output = (string) \Drupal::service('renderer')->renderRoot($output);
// The area output should not be present since access was denied.
$this->assertStringNotContainsString('a custom string', $output);
$view->destroy();
// Test with access granted for the area handler.
$view = Views::getView('test_example_area_access');
$view->initDisplay();
$view->display_handler
->overrideOption('empty', [
'test_example' => [
'field' => 'test_example',
'id' => 'test_example',
'table' => 'views',
'plugin_id' => 'test_example',
'string' => 'a custom string',
'custom_access' => TRUE,
],
]);
$view->initHandlers();
$handlers = $view->display_handler
->getHandlers('empty');
$output = $view->preview();
$output = (string) \Drupal::service('renderer')->renderRoot($output);
$this->assertStringContainsString('a custom string', $output);
$this->assertCount(1, $handlers);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.