You are here

protected function CacheTest::setFieldStorageSettings in Field Encryption 3.0.x

Set up storage settings for test fields.

Parameters

bool $encryption: Whether or not the fields should be encrypted. Defaults to TRUE.

Overrides FieldEncryptTestBase::setFieldStorageSettings

1 call to CacheTest::setFieldStorageSettings()
CacheTest::setUp in tests/src/Functional/CacheTest.php
@TODO: Simplify setUp() by extending EncryptTestBase when https://www.drupal.org/node/2692387 lands.

File

tests/src/Functional/CacheTest.php, line 114

Class

CacheTest
Tests field encryption caching.

Namespace

Drupal\Tests\field_encrypt\Functional

Code

protected function setFieldStorageSettings($encryption = TRUE) {
  $fields = [
    'node.field_test_single' => [
      'properties' => [
        'value' => 'value',
        'summary' => 'summary',
      ],
    ],
    'node.field_test_multi' => [
      'properties' => [
        'value' => 'value',
      ],
    ],
  ];
  foreach ($fields as $field => $settings) {
    $field_storage = FieldStorageConfig::load($field);
    if ($encryption) {
      $field_storage
        ->setThirdPartySetting('field_encrypt', 'encrypt', TRUE);
      $field_storage
        ->setThirdPartySetting('field_encrypt', 'properties', $settings['properties']);
    }
    else {
      $field_storage
        ->unsetThirdPartySetting('field_encrypt', 'encrypt');
      $field_storage
        ->unsetThirdPartySetting('field_encrypt', 'properties');
    }
    $field_storage
      ->save();
  }
}