You are here

public function JsonFormatterTest::testFormatterWithData in JSON Field 8

Tests that the formatter is rendering data.

File

tests/src/Kernel/JsonFormatterTest.php, line 43

Class

JsonFormatterTest
@coversDefaultClass \Drupal\json_field\Plugin\Field\FieldFormatter\JSONFormatter

Namespace

Drupal\Tests\json_field\Kernel

Code

public function testFormatterWithData() {
  $this
    ->createTestField([]);
  $entity_view_display = EntityViewDisplay::create([
    'targetEntityType' => 'entity_test',
    'bundle' => 'entity_test',
    'mode' => 'default',
  ]);
  $entity_view_display
    ->setComponent('test_json_field', []);
  $entity_view_display
    ->save();
  $entity = EntityTest::create([
    'test_json_field' => json_encode([
      'Looking for a' => 'complication',
    ]),
  ]);
  $entity
    ->save();
  $build = $entity_view_display
    ->build($entity);
  $content = $this->container
    ->get('renderer')
    ->renderRoot($build);
  $this
    ->assertEquals('<pre><code>{"Looking for a":"complication"}</code></pre>', $content);
}