You are here

public function HandlerFieldFieldTest::doTestFormatterSimpleFieldRender in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/field/tests/src/Kernel/Views/HandlerFieldFieldTest.php \Drupal\Tests\field\Kernel\Views\HandlerFieldFieldTest::doTestFormatterSimpleFieldRender()
  2. 10 core/modules/field/tests/src/Kernel/Views/HandlerFieldFieldTest.php \Drupal\Tests\field\Kernel\Views\HandlerFieldFieldTest::doTestFormatterSimpleFieldRender()

Tests that fields with formatters runs as expected.

1 call to HandlerFieldFieldTest::doTestFormatterSimpleFieldRender()
HandlerFieldFieldTest::testFieldRender in core/modules/field/tests/src/Kernel/Views/HandlerFieldFieldTest.php
Tests fields rendering in views.

File

core/modules/field/tests/src/Kernel/Views/HandlerFieldFieldTest.php, line 148

Class

HandlerFieldFieldTest
Tests the field rendering in views.

Namespace

Drupal\Tests\field\Kernel\Views

Code

public function doTestFormatterSimpleFieldRender() {
  $view = Views::getView('test_view_fieldapi');
  $this
    ->prepareView($view);
  $view->displayHandlers
    ->get('default')->options['fields'][$this->fieldStorages[5]
    ->getName()]['type'] = 'text_trimmed';
  $view->displayHandlers
    ->get('default')->options['fields'][$this->fieldStorages[5]
    ->getName()]['settings'] = [
    'trim_length' => 3,
  ];
  $view
    ->preview();

  // Make sure that the formatter works as expected.
  // @todo Add a specific formatter in #3046722.
  // @see https://www.drupal.org/project/drupal/issues/3046722
  for ($i = 0; $i < 2; $i++) {
    $field_name = $this->fieldStorages[5]
      ->getName();
    $rendered_field = $view->style_plugin
      ->getField($i, $field_name);
    $this
      ->assertEquals(3, strlen(html_entity_decode($rendered_field)));
  }
}