EdgeEntityRemoveMemberEventTest.php in Apigee Edge 8
File
modules/apigee_edge_actions/tests/src/Kernel/Plugin/RulesEvent/EdgeEntityRemoveMemberEventTest.php
View source
<?php
namespace Drupal\Tests\apigee_edge_actions\Kernel\Plugin\RulesEvent;
use Drupal\rules\Context\ContextConfig;
use Drupal\Tests\apigee_edge_actions\Kernel\ApigeeEdgeActionsRulesKernelTestBase;
class EdgeEntityRemoveMemberEventTest extends ApigeeEdgeActionsRulesKernelTestBase {
public static $modules = [
'apigee_edge_actions',
'apigee_edge',
'apigee_edge_teams',
'apigee_mock_api_client',
'dblog',
'key',
'options',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('team_member_role');
}
public function testEvent() {
$rule = $this->expressionManager
->createRule();
$rule
->addAction('apigee_edge_actions_log_message', ContextConfig::create()
->setValue('message', "Member {{ member.first_name }} was removed from team {{ team.displayName }}.")
->process('message', 'rules_tokens'));
$config_entity = $this->storage
->create([
'id' => 'app_remove_member_rule',
'events' => [
[
'event_name' => 'apigee_edge_actions_entity_remove_member:team',
],
],
'expression' => $rule
->getConfiguration(),
]);
$config_entity
->save();
$team = $this
->createTeam();
$team_membership_manager = $this->container
->get('apigee_edge_teams.team_membership_manager');
$this
->addUserToTeam($team, $this->account);
$this->stack
->queueMockResponse('no_content');
$team_membership_manager
->removeMembers($team
->id(), [
$this->account
->getEmail(),
]);
$this
->assertLogsContains("Event apigee_edge_actions_entity_remove_member:team was dispatched.");
$this
->assertLogsContains("Member {$this->account->first_name->value} was removed from team {$team->getDisplayName()}.");
}
}