You are here

public function KeyValueItemTest::testFieldCreateWithDefaultValue in Key value field 8

Test field creation with default values.

File

tests/src/Kernel/KeyValueItemTest.php, line 31

Class

KeyValueItemTest
@coversDefaultClass \Drupal\key_value_field\Plugin\Field\FieldType\KeyValueItem @group key_value_field

Namespace

Drupal\Tests\key_value_field\Kernel

Code

public function testFieldCreateWithDefaultValue() {
  $field_settings = [
    'default_value' => [
      0 => [
        'value' => 'orange',
        'key' => 'apple',
      ],
    ],
  ];
  $this
    ->createTestField('key_value', [], $field_settings);
  $entity = EntityTest::create([]);
  $entity
    ->save();
  $this
    ->assertFalse($entity->test_key_value_field
    ->isEmpty());
  $this
    ->assertEquals('apple', $entity->test_key_value_field->key);
  $this
    ->assertEquals('orange', $entity->test_key_value_field->value);
  $this
    ->assertEquals(NULL, $entity->test_key_value_field->description);
}