You are here

public function FieldKernelTest::testRewrite in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Tests/Handler/FieldKernelTest.php \Drupal\views\Tests\Handler\FieldKernelTest::testRewrite()

Tests general rewriting of the output.

File

core/modules/views/src/Tests/Handler/FieldKernelTest.php, line 152
Contains \Drupal\views\Tests\Handler\FieldKernelTest.

Class

FieldKernelTest
Tests the generic field handler.

Namespace

Drupal\views\Tests\Handler

Code

public function testRewrite() {

  /** @var \Drupal\Core\Render\RendererInterface $renderer */
  $renderer = \Drupal::service('renderer');
  $view = Views::getView('test_view');
  $view
    ->initHandlers();
  $this
    ->executeView($view);
  $row = $view->result[0];
  $id_field = $view->field['id'];

  // Don't check the rewrite checkbox, so the text shouldn't appear.
  $id_field->options['alter']['text'] = $random_text = $this
    ->randomMachineName();
  $output = $renderer
    ->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
    return $id_field
      ->theme($row);
  });
  $this
    ->assertNotSubString($output, $random_text);
  $id_field->options['alter']['alter_text'] = TRUE;
  $output = $renderer
    ->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
    return $id_field
      ->theme($row);
  });
  $this
    ->assertSubString($output, $random_text);
}