You are here

public function FieldKernelTest::testRender in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Kernel/Handler/FieldKernelTest.php \Drupal\Tests\views\Kernel\Handler\FieldKernelTest::testRender()

Tests that the render function is called.

File

core/modules/views/tests/src/Kernel/Handler/FieldKernelTest.php, line 51

Class

FieldKernelTest
Tests the generic field handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testRender() {

  /** @var \Drupal\Core\Render\RendererInterface $renderer */
  $renderer = \Drupal::service('renderer');
  $view = Views::getView('test_field_tokens');
  $this
    ->executeView($view);
  $random_text = $this
    ->randomMachineName();
  $view->field['job']
    ->setTestValue($random_text);
  $output = $renderer
    ->executeInRenderContext(new RenderContext(), function () use ($view) {
    return $view->field['job']
      ->theme($view->result[0]);
  });
  $this
    ->assertEquals($random_text, $output, 'Make sure the render method rendered the manual set value.');
}