SystemEmailToUsersOfRoleTest.php in Apigee Edge 8
File
modules/apigee_edge_actions/tests/src/Kernel/Plugin/RulesAction/SystemEmailToUsersOfRoleTest.php
View source
<?php
namespace Drupal\Tests\apigee_edge_actions\Kernel\Plugin\RulesAction;
use Drupal\rules\Context\ContextConfig;
use Drupal\Tests\apigee_edge_actions\Kernel\ApigeeEdgeActionsRulesKernelTestBase;
class SystemEmailToUsersOfRoleTest extends ApigeeEdgeActionsRulesKernelTestBase {
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();
$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');
}
}