You are here

public function JsonItemTest::testFieldCreateWithDefaultValue in JSON Field 8

Tests that default values are used when no value is added.

File

tests/src/Kernel/JsonItemTest.php, line 34

Class

JsonItemTest
@coversDefaultClass \Drupal\json_field\Plugin\Field\FieldType\JSONItem

Namespace

Drupal\Tests\json_field\Kernel

Code

public function testFieldCreateWithDefaultValue() {
  $field_settings = [
    'default_value' => [
      0 => [
        'value' => json_encode([
          'hey' => 'joe',
        ]),
      ],
    ],
  ];
  $this
    ->createTestField([], $field_settings);
  $entity = EntityTest::create([]);
  $entity
    ->save();
  $this
    ->assertEquals(json_encode([
    'hey' => 'joe',
  ]), $entity->test_json_field->value);
}