You are here

public function EdgeEntityUpdateEventTest::testEvent in Apigee Edge 8

Tests update events for Edge entities.

Throws

\Drupal\Core\Entity\EntityStorageException

\Drupal\rules\Exception\LogicException

File

modules/apigee_edge_actions/tests/src/Kernel/Plugin/RulesEvent/EdgeEntityUpdateEventTest.php, line 42

Class

EdgeEntityUpdateEventTest
Tests Edge entity update event.

Namespace

Drupal\Tests\apigee_edge_actions\Kernel\Plugin\RulesEvent

Code

public function testEvent() {

  // Create an update rule.
  $rule = $this->expressionManager
    ->createRule();
  $rule
    ->addAction('apigee_edge_actions_log_message', ContextConfig::create()
    ->setValue('message', "App {{ developer_app_unchanged.displayName }} was renamed to {{ developer_app.displayName }}.")
    ->process('message', 'rules_tokens'));
  $config_entity = $this->storage
    ->create([
    'id' => 'app_update_rule',
    'events' => [
      [
        'event_name' => 'apigee_edge_actions_entity_update:developer_app',
      ],
    ],
    'expression' => $rule
      ->getConfiguration(),
  ]);
  $config_entity
    ->save();

  // Insert and update entity.

  /** @var \Drupal\apigee_edge\Entity\DeveloperAppInterface $entity */
  $entity = $this
    ->createDeveloperApp();
  $original_name = $entity
    ->getDisplayName();
  $new_name = $this->randomGenerator
    ->name();
  $this
    ->queueDeveloperAppResponse($entity);
  $entity
    ->setDisplayName($new_name);
  $this
    ->queueDeveloperAppResponse($entity);
  $entity
    ->save();
  $this
    ->assertLogsContains("Event apigee_edge_actions_entity_update:developer_app was dispatched.");
  $this
    ->assertLogsContains("App {$original_name} was renamed to {$new_name}.");
}