You are here

public function KeyValueLongItemTest::testWithData in Key value field 8

Test storing data to field.

File

tests/src/Kernel/KeyValueLongItemTest.php, line 55

Class

KeyValueLongItemTest
@coversDefaultClass \Drupal\key_value_field\Plugin\Field\FieldType\KeyValueLongItem @group key_value_field

Namespace

Drupal\Tests\key_value_field\Kernel

Code

public function testWithData() {
  $this
    ->createTestField('key_value_long');
  $entity = EntityTest::create([
    'test_key_value_field' => [
      'value' => 'orange',
      'key' => 'apple',
    ],
  ]);
  $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);

  // Unless specified we fallback to the default, see
  // \Drupal\text\Plugin\Field\FieldType\TextItemBase::applyDefaultValue.
  $this
    ->assertEquals(NULL, $entity->test_key_value_field->format);
}