public function BaseFieldTest::testEncryptFieldRevision in Field Encryption 3.0.x
Test encrypting fields with revisions.
This test also covers deletion of an encrypted field with existing data.
File
- tests/
src/ Functional/ BaseFieldTest.php, line 198
Class
- BaseFieldTest
- Tests base field encryption.
Namespace
Drupal\Tests\field_encrypt\FunctionalCode
public function testEncryptFieldRevision() {
$this
->setFieldStorageSettings(TRUE);
// Save test entity.
$test_node = $this
->createNode([
'title' => 'Test title rev 1',
]);
// Create a new revision for the entity.
$old_revision_id = $test_node
->getRevisionId();
$test_node
->setNewRevision(TRUE);
$test_node->title->value = 'Test title rev 2';
$test_node
->save();
// Ensure that the node revision has been created.
\Drupal::entityTypeManager()
->getStorage('node')
->resetCache([
$test_node
->id(),
]);
$this
->assertNotSame($test_node
->getRevisionId(), $old_revision_id, 'A new revision has been created.');
// Check if revision text is displayed unencrypted.
$this
->drupalGet('node/' . $test_node
->id());
$this
->assertSession()
->pageTextContains('Test title rev 2');
// Check if original text is displayed unencrypted.
$this
->drupalGet('node/' . $test_node
->id() . '/revisions/' . $old_revision_id . '/view');
$this
->assertSession()
->pageTextContains("Test title rev 1");
// Check value saved in the database.
$result = \Drupal::database()
->query("SELECT title FROM {node_field_revision} WHERE nid = :entity_id", [
':entity_id' => $test_node
->id(),
])
->fetchField();
$this
->assertEquals(ProcessEntities::ENCRYPTED_VALUE, $result);
}