You are here

commerce_log_test.module in Commerce Core 8.2

Test module for Log.

File

modules/log/tests/module/commerce_log_test.module
View source
<?php

/**
 * @file
 * Test module for Log.
 */
use Drupal\Core\Entity\EntityInterface;

/**
 * Implements hook_ENTITY_TYPE_insert().
 */
function commerce_log_test_entity_test_insert(EntityInterface $entity) {

  /** @var \Drupal\commerce_log\LogStorageInterface $log_storage */
  $log_storage = \Drupal::entityTypeManager()
    ->getStorage('commerce_log');
  $params = [
    'entity_label' => $entity
      ->label(),
  ];
  $log = $log_storage
    ->generate($entity, 'entity_test_created', $params);
  $log
    ->save();
}

/**
 * Implements hook_mail_alter().
 */
function commerce_log_test_mail_alter(&$message) {
  if (!isset($message['params']['order'])) {
    return;
  }

  /** @var \Drupal\commerce_order\Entity\OrderInterface $order */
  $order = $message['params']['order'];
  if ($order
    ->getData('simulate_mail_failure')) {
    $message['send'] = FALSE;
  }
}