FieldLinkTest.php in (Entity Reference) Field Formatters 3.x
File
tests/src/Kernel/Plugin/Field/FieldFormatter/FieldLinkTest.php
View source
<?php
namespace Drupal\Tests\field_formatter\Kernel\Plugin\Field\FieldFormatter;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\KernelTests\KernelTestBase;
class FieldLinkTest extends KernelTestBase {
public static $modules = [
'entity_test',
'field_formatter',
'user',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('entity_test');
$this
->installEntitySchema('user');
}
public function testFieldLinkFormatter() {
$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');
}
}