function FieldKernelTest::testRender

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/Handler/FieldKernelTest.php \Drupal\Tests\views\Kernel\Handler\FieldKernelTest::testRender()
  2. 10 core/modules/views/tests/src/Kernel/Handler/FieldKernelTest.php \Drupal\Tests\views\Kernel\Handler\FieldKernelTest::testRender()
  3. 11.x 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->assertEqual($output, $random_text, 'Make sure the render method rendered the manual set value.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.