AreaTextTest.php in Drupal 10
File
core/modules/views/tests/src/Kernel/Handler/AreaTextTest.php
View source
<?php
namespace Drupal\Tests\views\Kernel\Handler;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Views;
class AreaTextTest extends ViewsKernelTestBase {
protected static $modules = [
'system',
'user',
'filter',
];
public static $testViews = [
'test_view',
];
protected function setUp($import_test_views = TRUE) : void {
parent::setUp();
$this
->installConfig([
'system',
'filter',
]);
$this
->installEntitySchema('user');
}
public function testAreaText() {
$renderer = $this->container
->get('renderer');
$view = Views::getView('test_view');
$view
->setDisplay();
$string = $this
->randomMachineName();
$view->displayHandlers
->get('default')
->overrideOption('header', [
'area' => [
'id' => 'area',
'table' => 'views',
'field' => 'area',
'content' => [
'value' => $string,
],
],
]);
$this
->executeView($view);
$view->display_handler->handlers['header']['area']->options['content']['format'] = $this
->randomString();
$build = $view->display_handler->handlers['header']['area']
->render();
$this
->assertEquals('', $renderer
->renderRoot($build), 'Nonexistent format should return empty markup.');
$view->display_handler->handlers['header']['area']->options['content']['format'] = filter_default_format();
$build = $view->display_handler->handlers['header']['area']
->render();
$this
->assertEquals(check_markup($string), $renderer
->renderRoot($build), 'Existent format should return something');
$this
->assertEquals([], $view->display_handler->handlers['header']['area']
->render(TRUE), 'No result should lead to no header');
$view->display_handler->handlers['header']['area']->options['empty'] = TRUE;
$build = $view->display_handler->handlers['header']['area']
->render(TRUE);
$this
->assertEquals(check_markup($string), $renderer
->renderRoot($build), 'No result, but empty enabled lead to a full header');
}
}