function HandlerFieldFieldTest::doTestFormatterSimpleFieldRender

Same name in other branches
  1. 9 core/modules/field/tests/src/Kernel/Views/HandlerFieldFieldTest.php \Drupal\Tests\field\Kernel\Views\HandlerFieldFieldTest::doTestFormatterSimpleFieldRender()
  2. 8.9.x core/modules/field/tests/src/Kernel/Views/HandlerFieldFieldTest.php \Drupal\Tests\field\Kernel\Views\HandlerFieldFieldTest::doTestFormatterSimpleFieldRender()
  3. 11.x 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 153

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 = (string) $view->style_plugin
            ->getField($i, $field_name);
        $this->assertEquals(3, strlen(html_entity_decode($rendered_field)));
    }
}

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