function FieldFieldTest::testFieldApiClassesRender

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/Handler/FieldFieldTest.php \Drupal\Tests\views\Kernel\Handler\FieldFieldTest::testFieldApiClassesRender()
  2. 11.x core/modules/views/tests/src/Kernel/Handler/FieldFieldTest.php \Drupal\Tests\views\Kernel\Handler\FieldFieldTest::testFieldApiClassesRender()

Tests the result of a view field with field_api_classes enabled.

File

core/modules/views/tests/src/Kernel/Handler/FieldFieldTest.php, line 350

Class

FieldFieldTest
Provides some integration tests for the Field handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testFieldApiClassesRender() : void {
    
    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = $this->container
        ->get('renderer');
    $executable = Views::getView('test_field_field_test');
    $executable->initHandlers();
    // Enable field_api_classes for the id field.
    $id_field = $executable->field['id'];
    $id_field->options['field_api_classes'] = TRUE;
    // Test that the ID field renders with multiple divs from field template.
    $output = $executable->preview();
    $output = $renderer->renderRoot($output);
    $this->setRawContent($output);
    $field_values = $this->xpath('//div[contains(@class, "views-field-id")]/span[contains(@class, :class)]/div', [
        ':class' => 'field-content',
    ]);
    $this->assertNotEmpty($field_values);
}

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