function FieldDisplayTest::testFieldVisualHidden

Same name in other branches
  1. 9 core/modules/field/tests/src/Kernel/FieldDisplayTest.php \Drupal\Tests\field\Kernel\FieldDisplayTest::testFieldVisualHidden()
  2. 8.9.x core/modules/field/tests/src/Kernel/FieldDisplayTest.php \Drupal\Tests\field\Kernel\FieldDisplayTest::testFieldVisualHidden()
  3. 10 core/modules/field/tests/src/Kernel/FieldDisplayTest.php \Drupal\Tests\field\Kernel\FieldDisplayTest::testFieldVisualHidden()

Tests that visually hidden works with core.

File

core/modules/field/tests/src/Kernel/FieldDisplayTest.php, line 102

Class

FieldDisplayTest
Tests Field display.

Namespace

Drupal\Tests\field\Kernel

Code

public function testFieldVisualHidden() : void {
    $value = $this->randomMachineName();
    // Set the formatter to link to the entity.
    $this->display
        ->setComponent($this->fieldName, [
        'type' => 'string',
        'label' => 'visually_hidden',
        'settings' => [],
    ])
        ->save();
    $entity = EntityTestRev::create([]);
    $entity->{$this->fieldName}->value = $value;
    $entity->save();
    $build = $this->display
        ->build($entity);
    $renderer = \Drupal::service('renderer');
    $content = (string) $renderer->renderInIsolation($build);
    $this->setRawContent($content);
    $css_selector_converter = new CssSelectorConverter();
    $elements = $this->xpath($css_selector_converter->toXPath('.visually-hidden'));
    $this->assertCount(1, $elements, $content);
}

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