public function EdgeEntityRemoveProductEventTest::testEvent in Apigee Edge 8
Tests add_member events for Edge entities.
Throws
\Drupal\Core\Entity\EntityStorageException
\Drupal\rules\Exception\LogicException
File
- modules/
apigee_edge_actions/ tests/ src/ Kernel/ Plugin/ RulesEvent/ EdgeEntityRemoveProductEventTest.php, line 57
Class
- EdgeEntityRemoveProductEventTest
- Tests Edge entity remove_product event.
Namespace
Drupal\Tests\apigee_edge_actions\Kernel\Plugin\RulesEventCode
public function testEvent() {
// Create an insert rule.
$rule = $this->expressionManager
->createRule();
$rule
->addAction('apigee_edge_actions_log_message', ContextConfig::create()
->setValue('message', "Product {{ api_product_name }} was removed from app {{ developer_app.name }}.")
->process('message', 'rules_tokens'));
$config_entity = $this->storage
->create([
'id' => 'app_insert_rule',
'events' => [
[
'event_name' => 'apigee_edge_actions_entity_remove_product:developer_app',
],
],
'expression' => $rule
->getConfiguration(),
]);
$config_entity
->save();
/** @var \Drupal\apigee_edge\Entity\AppInterface $developer_app */
$developer_app = $this
->createDeveloperApp();
$api_product = ApiProduct::create([
'name' => $this
->randomMachineName(),
'displayName' => $this
->getRandomGenerator()
->word(16),
'approvalType' => ApiProduct::APPROVAL_TYPE_AUTO,
]);
/** @var \Drupal\apigee_edge\Entity\ApiProduct $api_product */
$this->stack
->queueMockResponse([
'api_product' => [
'product' => $api_product,
],
]);
$api_product
->save();
$this->stack
->queueMockResponse([
'api_product' => [
'product' => $api_product,
],
]);
$this
->queueDeveloperResponse($this->account);
$this
->queueDeveloperAppResponse($developer_app);
/** @var \Drupal\apigee_edge\Entity\Controller\DeveloperAppCredentialControllerFactoryInterface $credential_factory */
$credential_factory = \Drupal::service('apigee_edge.controller.developer_app_credential_factory');
/** @var \Drupal\apigee_edge\Entity\Controller\AppCredentialControllerInterface $app_credential_controller */
$app_credential_controller = $credential_factory
->developerAppCredentialController($this->account
->uuid(), $developer_app
->getName());
$consumer_key = $this
->randomString();
$app_credential_controller
->addProducts($consumer_key, [
$api_product
->id(),
]);
$this->stack
->queueMockResponse([
'api_product' => [
'product' => $api_product,
],
]);
$app_credential_controller
->deleteApiProduct($consumer_key, $api_product
->id());
$this
->assertLogsContains("Event apigee_edge_actions_entity_remove_product:developer_app was dispatched.");
$this
->assertLogsContains("Product {$api_product->getName()} was removed from app {$developer_app->getName()}.");
}