trait WorkbenchEmailTestTrait in Workbench Email 8
Same name and namespace in other branches
- 2.x tests/src/Traits/WorkbenchEmailTestTrait.php \Drupal\Tests\workbench_email\Traits\WorkbenchEmailTestTrait
Contains helper classes for tests to set up various configuration.
Hierarchy
- trait \Drupal\Tests\workbench_email\Traits\WorkbenchEmailTestTrait
2 files declare their use of WorkbenchEmailTestTrait
- ConfigDependenciesTest.php in tests/
src/ Kernel/ ConfigDependenciesTest.php - RecipientTypePluginsTest.php in tests/
src/ Kernel/ RecipientTypePluginsTest.php
File
- tests/
src/ Traits/ WorkbenchEmailTestTrait.php, line 14
Namespace
Drupal\Tests\workbench_email\TraitsView source
trait WorkbenchEmailTestTrait {
/**
* Enables moderation for a given node type.
*
* @param \Drupal\node\NodeTypeInterface $node_type
* Node type to enable moderation for.
*/
protected function setUpModerationForNodeType(NodeTypeInterface $node_type) {
$node_type
->setThirdPartySetting('workbench_moderation', 'enabled', TRUE);
$states = array_keys(ModerationState::loadMultiple());
$node_type
->setThirdPartySetting('workbench_moderation', 'allowed_moderation_states', $states);
$node_type
->setThirdPartySetting('workbench_moderation', 'default_moderation_state', 'draft');
$node_type
->save();
}
/**
* Adds an email field to a node bundle.
*
* @param string $bundle
* (optional) Bundle name. Defaults to 'test'.
*/
protected function setUpEmailFieldForNodeBundle($bundle = 'test') {
// Add an email field notify to the bundle.
FieldStorageConfig::create([
'cardinality' => 1,
'entity_type' => 'node',
'field_name' => 'field_email',
'type' => 'email',
])
->save();
FieldConfig::create([
'field_name' => 'field_email',
'bundle' => 'test',
'label' => 'Notify',
'entity_type' => 'node',
])
->save();
if (!($entity_form_display = EntityFormDisplay::load(sprintf('node.%s.default', $bundle)))) {
$entity_form_display = EntityFormDisplay::create([
'targetEntityType' => 'node',
'bundle' => $bundle,
'mode' => 'default',
'status' => TRUE,
]);
}
$entity_form_display
->setComponent('field_email', [
'type' => 'email_default',
])
->save();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
WorkbenchEmailTestTrait:: |
protected | function | Adds an email field to a node bundle. | |
WorkbenchEmailTestTrait:: |
protected | function | Enables moderation for a given node type. |