ComputedFieldTest.php in Drupal 9
File
core/modules/views/tests/src/Kernel/Handler/ComputedFieldTest.php
View source
<?php
namespace Drupal\Tests\views\Kernel\Handler;
use Drupal\entity_test\Entity\EntityTestComputedField;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Views;
class ComputedFieldTest extends ViewsKernelTestBase {
public static $testViews = [
'computed_field_view',
];
protected static $modules = [
'entity_test',
];
protected function setUp($import_test_views = TRUE) : void {
parent::setUp($import_test_views);
$this
->installEntitySchema('entity_test_computed_field');
}
public function testComputedFieldHandler() {
\Drupal::state()
->set('entity_test_computed_field_item_list_value', [
'computed string',
]);
$entity = EntityTestComputedField::create([]);
$entity
->save();
$view = Views::getView('computed_field_view');
$rendered_view = $view
->preview();
$output = $this->container
->get('renderer')
->renderRoot($rendered_view);
$this
->assertStringContainsString('computed string', (string) $output);
}
}