You are here

protected function EncryptingExistingDataTest::assertConfigurableFieldEncrypted in Field Encryption 3.0.x

Asserts that configurable fields are encrypted as expected.

Parameters

int $node_id: The node ID to check.

1 call to EncryptingExistingDataTest::assertConfigurableFieldEncrypted()
EncryptingExistingDataTest::testEncryptingExistingData in tests/src/Functional/EncryptingExistingDataTest.php
Tests that existing entities can be encrypted.

File

tests/src/Functional/EncryptingExistingDataTest.php, line 135

Class

EncryptingExistingDataTest
Tests encrypting fields on entities that already exist.

Namespace

Drupal\Tests\field_encrypt\Functional

Code

protected function assertConfigurableFieldEncrypted($node_id) {
  $result = \Drupal::database()
    ->query("SELECT field_test_single_value FROM {node__field_test_single} WHERE entity_id = :entity_id", [
    ':entity_id' => $node_id,
  ])
    ->fetchField();
  $this
    ->assertEquals(ProcessEntities::ENCRYPTED_VALUE, $result);
  $result = \Drupal::database()
    ->query("SELECT field_test_multi_value FROM {node__field_test_multi} WHERE entity_id = :entity_id", [
    ':entity_id' => $node_id,
  ])
    ->fetchAll();
  foreach ($result as $record) {
    $this
      ->assertEquals(ProcessEntities::ENCRYPTED_VALUE, $record->field_test_multi_value);
  }

  // Revisions.
  $result = \Drupal::database()
    ->query("SELECT field_test_single_value FROM {node_revision__field_test_single} WHERE entity_id = :entity_id", [
    ':entity_id' => $node_id,
  ])
    ->fetchAll();
  foreach ($result as $record) {
    $this
      ->assertEquals(ProcessEntities::ENCRYPTED_VALUE, $record->field_test_single_value);
  }
  $result = \Drupal::database()
    ->query("SELECT field_test_multi_value FROM {node_revision__field_test_multi} WHERE entity_id = :entity_id", [
    ':entity_id' => $node_id,
  ])
    ->fetchAll();
  foreach ($result as $record) {
    $this
      ->assertEquals(ProcessEntities::ENCRYPTED_VALUE, $record->field_test_multi_value);
  }
}