public function SystemEmailToUsersOfRoleTest::testAction in Apigee Edge 8
Tests sending email to role event.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
\Drupal\Core\Entity\EntityStorageException
\Drupal\rules\Exception\LogicException
File
- modules/
apigee_edge_actions/ tests/ src/ Kernel/ Plugin/ RulesAction/ SystemEmailToUsersOfRoleTest.php, line 44
Class
- SystemEmailToUsersOfRoleTest
- Tests Edge entity add_member event.
Namespace
Drupal\Tests\apigee_edge_actions\Kernel\Plugin\RulesActionCode
public function testAction() {
$role_storage = $this->container
->get('entity_type.manager')
->getStorage('user_role');
$role_storage
->create([
'id' => 'test_role',
])
->save();
$this->account
->addRole('test_role');
$this
->queueDeveloperResponse($this->account);
$this->account
->activate();
$this->account
->save();
$rule = $this->expressionManager
->createRule();
$rule
->addAction('rules_email_to_users_of_role', ContextConfig::create()
->setValue('roles', [
'test_role',
])
->setValue('subject', 'Test email')
->setValue('message', 'This is a test email'));
$config_entity = $this->storage
->create([
'id' => 'send_email_to_admin_rule',
'events' => [
[
'event_name' => 'apigee_edge_actions_entity_insert:developer_app',
],
],
'expression' => $rule
->getConfiguration(),
]);
$config_entity
->save();
// Insert an entity to trigger rule.
$this
->queueDeveloperResponse($this->account);
$this
->createDeveloperApp();
$this
->assertLogsContains("Event apigee_edge_actions_entity_insert:developer_app was dispatched.");
$this
->assertLogsContains('Successfully sent email to <em class="placeholder">1</em> out of <em class="placeholder">1</em> users having the role(s) <em class="placeholder">test_role</em>', 'rules');
}