You are here

public function FieldLinkTest::testFieldLinkFormatter in (Entity Reference) Field Formatters 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/Plugin/Field/FieldFormatter/FieldLinkTest.php \Drupal\Tests\field_formatter\Kernel\Plugin\Field\FieldFormatter\FieldLinkTest::testFieldLinkFormatter()
  2. 3.x tests/src/Kernel/Plugin/Field/FieldFormatter/FieldLinkTest.php \Drupal\Tests\field_formatter\Kernel\Plugin\Field\FieldFormatter\FieldLinkTest::testFieldLinkFormatter()

@covers ::viewElements @covers ::getFieldOutput @covers ::getViewDisplay

File

tests/src/Kernel/Plugin/Field/FieldFormatter/FieldLinkTest.php, line 34

Class

FieldLinkTest
@coversDefaultClass \Drupal\field_formatter\Plugin\Field\FieldFormatter\FieldLink @group field_formatter

Namespace

Drupal\Tests\field_formatter\Kernel\Plugin\Field\FieldFormatter

Code

public function testFieldLinkFormatter() {

  /** @var \Drupal\entity_test\Entity\EntityTest $entity */
  $entity = EntityTest::create([
    'name' => 'test name',
  ]);
  $entity
    ->save();
  $build = $entity->name
    ->view([
    'type' => 'field_link',
    'settings' => [
      'type' => 'string',
    ],
  ]);
  $output = \Drupal::service('renderer')
    ->renderRoot($build);
  $this
    ->setRawContent($output);
  $href = (string) $this
    ->cssSelect('a')[0]
    ->attributes()['href'];
  $this
    ->assertEquals($href, $entity
    ->toUrl()
    ->toString(TRUE)
    ->getGeneratedUrl());
  $this
    ->assertText('test name');
}