You are here

public function KeyMultiValueTest::testMultiValuesAreSerialized in Key 8

Tests that multi-value keys get serialized.

File

tests/src/Kernel/KeyMultiValueTest.php, line 28

Class

KeyMultiValueTest
Defines a test for key multi-values.

Namespace

Drupal\Tests\key\Kernel

Code

public function testMultiValuesAreSerialized() {
  $key = Key::create([
    'id' => 'multi',
    'label' => 'Multi',
    'description' => 'Multi-value key',
    'key_type' => 'key_test_multi',
    'key_type_settings' => [],
    'key_provider' => 'key_test_state',
    'key_provider_settings' => [
      'state_key' => 'test_multivalue',
    ],
    'key_input' => 'key_test_multi',
    'key_test_multi_settings' => [
      'first' => 'something',
      'second' => 'else',
    ],
  ]);
  $key
    ->setKeyValue([
    'first' => 'woof',
    'second' => 'bark',
  ]);
  $key
    ->save();
  $this
    ->assertEquals(json_encode([
    'first' => 'woof',
    'second' => 'bark',
  ]), \Drupal::state()
    ->get('key_test:test_multivalue'));
}