class EntityHooksTest in Field Encryption 3.0.x
Tests Field encrypt's use_eval_for_entity_hooks setting.
@group field_encrypt
Hierarchy
- class \Drupal\Tests\field_encrypt\Functional\EntityHooksTest extends \Drupal\Tests\encrypt\Functional\EncryptTestBase uses NodeCreationTrait, CronRunTrait
Expanded class hierarchy of EntityHooksTest
File
- tests/
src/ Functional/ EntityHooksTest.php, line 14
Namespace
Drupal\Tests\field_encrypt\FunctionalView source
class EntityHooksTest extends EncryptTestBase {
use CronRunTrait;
use NodeCreationTrait;
/**
* {@inheritdoc}
*/
public static $modules = [
'node',
'field',
'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();
// Disable eval().
$settings['settings']['field_encrypt.use_eval_for_entity_hooks'] = (object) [
'value' => FALSE,
'required' => TRUE,
];
$this
->writeSettings($settings);
// Create an admin user.
$this->adminUser = $this
->drupalCreateUser([
'access administration pages',
'administer encrypt',
'administer keys',
'administer field encryption',
], NULL, TRUE);
$this
->drupalLogin($this->adminUser);
// Create content type to test.
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic page',
]);
$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('Content');
$this
->submitForm([], 'Save configuration');
if ($encryption) {
$this
->assertSession()
->fieldExists('base_fields[title]')
->check();
}
else {
$this
->assertSession()
->fieldExists('base_fields[title]')
->uncheck();
}
$this
->submitForm([], 'Save configuration');
$this
->assertSession()
->pageTextContains('Updated encryption settings for Content base fields.');
$this
->rebuildAll();
}
/**
* Tests field_encrypt prints code on status report when eval() disabled.
*/
public function testStatusReport() {
$this
->drupalGet('admin/reports/status');
$this
->assertSession()
->pageTextNotContains('Field Encrypt entity hooks');
$this
->setFieldStorageSettings(TRUE);
$this
->drupalGet('admin/reports/status');
$this
->assertSession()
->pageTextContains('Field Encrypt entity hooks');
$this
->assertSession()
->pageTextContains('function field_encrypt_node_insert(');
$this
->assertSession()
->pageTextContains('function field_encrypt_node_update(');
// Enable eval().
$settings['settings']['field_encrypt.use_eval_for_entity_hooks'] = (object) [
'value' => TRUE,
'required' => TRUE,
];
$this
->writeSettings($settings);
$this
->rebuildAll();
$this
->drupalGet('admin/reports/status');
$this
->assertSession()
->pageTextNotContains('Field Encrypt entity hooks');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CronRunTrait:: |
protected | function | Runs cron on the test site. | |
EntityHooksTest:: |
public static | property | ||
EntityHooksTest:: |
protected | function | Set up base fields for test. | |
EntityHooksTest:: |
protected | function | @TODO: Simplify setUp() by extending EncryptTestBase when https://www.drupal.org/node/2692387 lands. | |
EntityHooksTest:: |
public | function | Tests field_encrypt prints code on status report when eval() disabled. | |
NodeCreationTrait:: |
protected | function | Creates a node based on default settings. | |
NodeCreationTrait:: |
public | function | Get a node from the database based on its title. |