AreaEmptyTest.php in Drupal 10
File
core/modules/views/tests/src/Kernel/Handler/AreaEmptyTest.php
View source
<?php
namespace Drupal\Tests\views\Kernel\Handler;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Views;
class AreaEmptyTest extends ViewsKernelTestBase {
protected static $modules = [
'node',
];
protected function setUp($import_test_views = TRUE) : void {
parent::setUp();
$this
->installEntitySchema('node');
}
protected function viewsData() {
$data = parent::viewsData();
$data['views']['test_example'] = [
'title' => 'Test Example area',
'help' => 'A area handler which just exists for tests.',
'area' => [
'id' => 'test_example',
],
];
return $data;
}
public static $testViews = [
'test_example_area',
];
public function testRenderEmptyHeaderFooter() {
$view = Views::getView('test_example_area');
$view
->initHandlers();
$empty_text = $this
->randomMachineName();
$empty_header = $this
->randomMachineName();
$empty_footer = $this
->randomMachineName();
$view->empty['test_example']->options['string'] = '<p>' . $empty_text . '</p>';
$view->header['test_example']->options['string'] = '<p>' . $empty_header . '</p>';
$view->footer['test_example']->options['string'] = '<p>' . $empty_footer . '</p>';
$view
->setDisplay('default');
$this
->executeView($view);
$output = $view
->render();
$output = \Drupal::service('renderer')
->renderRoot($output);
$this
->setRawContent($output);
$this
->assertText($empty_text);
$this
->assertNoText($empty_header);
$this
->assertNoText($empty_footer);
$view->header['test_example']->options['empty'] = TRUE;
$view->footer['test_example']->options['empty'] = TRUE;
$this
->executeView($view);
$output = $view
->render();
$output = \Drupal::service('renderer')
->renderRoot($output);
$this
->setRawContent($output);
$this
->assertText($empty_header);
$this
->assertText($empty_footer);
}
}