You are here

public function KeyValueFormatterTest::testFormatter in Key value field 8

Tests default formatter settings.

File

tests/src/Kernel/KeyValueFormatterTest.php, line 17

Class

KeyValueFormatterTest
@coversDefaultClass \Drupal\key_value_field\Plugin\Field\FieldFormatter\KeyValueFormatter @group key_value_field

Namespace

Drupal\Tests\key_value_field\Kernel

Code

public function testFormatter() {
  $this
    ->createTestField('key_value');
  $entity_view_display = EntityViewDisplay::create([
    'targetEntityType' => 'entity_test',
    'bundle' => 'entity_test',
    'mode' => 'default',
  ]);
  $entity_view_display
    ->setComponent('test_key_value_field', [
    'type' => 'key_value',
  ]);
  $entity_view_display
    ->save();
  $entity = EntityTest::create([
    'test_key_value_field' => [
      'value' => "orange",
      'key' => 'apple',
    ],
  ]);
  $entity
    ->save();
  $build = $entity_view_display
    ->build($entity);
  $output = $this
    ->render($build);

  // AssertRaw needs content to be set.
  $this
    ->setRawContent($output);
  $this
    ->assertRaw("apple : <p>orange</p>\n");
}