public function AreaTest::testAreaAccess in Drupal 10
Same name and namespace in other branches
- 8 core/modules/views/tests/src/Functional/Handler/AreaTest.php \Drupal\Tests\views\Functional\Handler\AreaTest::testAreaAccess()
- 9 core/modules/views/tests/src/Functional/Handler/AreaTest.php \Drupal\Tests\views\Functional\Handler\AreaTest::testAreaAccess()
Tests the access for an area.
File
- core/
modules/ views/ tests/ src/ Functional/ Handler/ AreaTest.php, line 126
Class
- AreaTest
- Tests the plugin base of the area handler.
Namespace
Drupal\Tests\views\Functional\HandlerCode
public function testAreaAccess() {
// 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 = \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 = \Drupal::service('renderer')
->renderRoot($output);
$this
->assertStringContainsString('a custom string', $output);
$this
->assertCount(1, $handlers);
}