You are here

public function JsonFormatterTest::testFormatter in JSON Field 8

Tests that the formatter is rendering an empty array.

File

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

Class

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

Namespace

Drupal\Tests\json_field\Kernel

Code

public function testFormatter() {
  $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([]),
  ]);
  $entity
    ->save();
  $build = $entity_view_display
    ->build($entity);
  $content = $this->container
    ->get('renderer')
    ->renderRoot($build);
  $this
    ->assertEquals('<pre><code>[]</code></pre>', $content);
}