class EncryptUserTest in Field Encryption 3.0.x
Tests user field encryption.
@group field_encrypt
Hierarchy
- class \Drupal\Tests\field_encrypt\Functional\EncryptUserTest extends \Drupal\Tests\encrypt\Functional\EncryptTestBase uses EntityDefinitionTestTrait, CronRunTrait
Expanded class hierarchy of EncryptUserTest
File
- tests/
src/ Functional/ EncryptUserTest.php, line 15
Namespace
Drupal\Tests\field_encrypt\FunctionalView source
class EncryptUserTest extends EncryptTestBase {
use EntityDefinitionTestTrait;
use CronRunTrait;
/**
* {@inheritdoc}
*/
public static $modules = [
'field',
'field_ui',
'text',
'key',
'encrypt',
'encrypt_test',
'field_encrypt',
'field_encrypt_test',
];
/**
* {@inheritdoc}
*
* @TODO: Simplify setUp() by extending EncryptTestBase when https://www.drupal.org/node/2692387 lands.
*/
protected function setUp() {
parent::setUp();
// Create an admin user.
$this->adminUser = $this
->drupalCreateUser([
'access administration pages',
'administer encrypt',
'administer keys',
'administer field encryption',
], NULL, TRUE);
// Set a value for init so it gets encrypted.
$this->adminUser->init = 'test@example.com';
$this->adminUser
->save();
$this
->drupalLogin($this->adminUser);
$this
->config('field_encrypt.settings')
->set('encryption_profile', 'encryption_profile_1')
->save();
}
/**
* Set up base fields for test.
*
* @param bool $encryption
* Whether or not the fields should be encrypted. Defaults to TRUE.
*/
protected function setFieldStorageSettings($encryption = TRUE) {
// Set up storage settings for first field.
$this
->drupalGet('admin/config/system/field-encrypt/entity-types');
$this
->assertSession()
->fieldExists('entity_type')
->selectOption('User');
$this
->submitForm([], 'Save configuration');
if ($encryption) {
$this
->assertSession()
->fieldExists('base_fields[init]')
->check();
}
else {
$this
->assertSession()
->fieldExists('base_fields[init]')
->uncheck();
}
$this
->submitForm([], 'Save configuration');
$this
->assertSession()
->pageTextContains('Updated encryption settings for User base fields.');
$this
->rebuildAll();
}
/**
* Test encrypting user fields.
*
* This test covers encrypting non-revisionable entities as well.
*/
public function testEncryptFieldNormal() {
$this
->setFieldStorageSettings(TRUE);
$this
->drupalGet('admin/config/system/field-encrypt/process-queues');
$this
->assertSession()
->pageTextContains('There are 4 entities queued for updating to use the latest field encryption settings.');
$this
->cronRun();
$this
->drupalGet('admin/config/system/field-encrypt/process-queues');
$this
->assertSession()
->pageTextContains('There are 0 entities queued for updating to use the latest field encryption settings.');
$result = \Drupal::database()
->query("SELECT init FROM {users_field_data} WHERE uid = :uid", [
':uid' => $this->adminUser
->id(),
])
->fetchAll();
$this
->assertCount(1, $result);
foreach ($result as $record) {
$this
->assertEquals(ProcessEntities::ENCRYPTED_VALUE, $record->init);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CronRunTrait:: |
protected | function | Runs cron on the test site. | |
EncryptUserTest:: |
public static | property | ||
EncryptUserTest:: |
protected | function | Set up base fields for test. | |
EncryptUserTest:: |
protected | function | @TODO: Simplify setUp() by extending EncryptTestBase when https://www.drupal.org/node/2692387 lands. | |
EncryptUserTest:: |
public | function | Test encrypting user fields. | |
EntityDefinitionTestTrait:: |
protected | function | Adds a new base field to the 'entity_test_update' entity type. | |
EntityDefinitionTestTrait:: |
protected | function | Adds a single-field index to the base field. | |
EntityDefinitionTestTrait:: |
protected | function | Adds a new bundle field to the 'entity_test_update' entity type. | |
EntityDefinitionTestTrait:: |
protected | function | Adds an index to the 'entity_test_update' entity type's base table. | |
EntityDefinitionTestTrait:: |
protected | function | Adds a long-named base field to the 'entity_test_update' entity type. | |
EntityDefinitionTestTrait:: |
protected | function | Adds a new revisionable base field to the 'entity_test_update' entity type. | |
EntityDefinitionTestTrait:: |
protected | function | Applies all the detected valid changes. | |
EntityDefinitionTestTrait:: |
protected | function | Removes the entity type. | |
EntityDefinitionTestTrait:: |
protected | function | Performs an entity type definition update. | |
EntityDefinitionTestTrait:: |
protected | function | Performs a field storage definition update. | |
EntityDefinitionTestTrait:: |
protected | function | Enables a new entity type definition. | |
EntityDefinitionTestTrait:: |
protected | function | Returns an entity type definition, possibly updated to be rev or mul. | |
EntityDefinitionTestTrait:: |
protected | function | Returns the required rev / mul field definitions for an entity type. | |
EntityDefinitionTestTrait:: |
protected | function | Promotes a field to an entity key. | |
EntityDefinitionTestTrait:: |
protected | function | Modifies the new base field from 'string' to 'text'. | |
EntityDefinitionTestTrait:: |
protected | function | Modifies the new bundle field from 'string' to 'text'. | |
EntityDefinitionTestTrait:: |
protected | function | Removes the new base field from the 'entity_test_update' entity type. | |
EntityDefinitionTestTrait:: |
protected | function | Removes the index added in addBaseFieldIndex(). | |
EntityDefinitionTestTrait:: |
protected | function | Removes the new bundle field from the 'entity_test_update' entity type. | |
EntityDefinitionTestTrait:: |
protected | function | Removes the index added in addEntityIndex(). | |
EntityDefinitionTestTrait:: |
protected | function | Renames the base table to 'entity_test_update_new'. | |
EntityDefinitionTestTrait:: |
protected | function | Renames the data table to 'entity_test_update_data_new'. | |
EntityDefinitionTestTrait:: |
protected | function | Renames the revision table to 'entity_test_update_revision_new'. | |
EntityDefinitionTestTrait:: |
protected | function | Renames the revision data table to 'entity_test_update_revision_data_new'. | |
EntityDefinitionTestTrait:: |
protected | function | Resets the entity type definition. | |
EntityDefinitionTestTrait:: |
protected | function | Updates the 'entity_test_update' entity type not revisionable. | |
EntityDefinitionTestTrait:: |
protected | function | Updates the 'entity_test_update' entity type to not translatable. | |
EntityDefinitionTestTrait:: |
protected | function | Updates the 'entity_test_update' entity type to revisionable. | |
EntityDefinitionTestTrait:: |
protected | function | Updates the 'entity_test_update' entity type to revisionable and translatable. | |
EntityDefinitionTestTrait:: |
protected | function | Updates the 'entity_test_update' entity type to translatable. |