You are here

trait ScheduledTransitionTestTrait in Scheduled Transitions 8

Same name and namespace in other branches
  1. 2.x tests/src/Traits/ScheduledTransitionTestTrait.php \Drupal\Tests\scheduled_transitions\Traits\ScheduledTransitionTestTrait

Test trait helpers.

Hierarchy

8 files declare their use of ScheduledTransitionTestTrait
ScheduledTransitionEntityTest.php in tests/src/Functional/ScheduledTransitionEntityTest.php
ScheduledTransitionEntityTransitionsFormTest.php in tests/src/Functional/ScheduledTransitionEntityTransitionsFormTest.php
ScheduledTransitionLocalTaskTest.php in tests/src/Functional/ScheduledTransitionLocalTaskTest.php
ScheduledTransitionModalFormTest.php in tests/src/Functional/ScheduledTransitionModalFormTest.php
ScheduledTransitionRescheduleFormTest.php in tests/src/Functional/ScheduledTransitionRescheduleFormTest.php

... See full list

File

tests/src/Traits/ScheduledTransitionTestTrait.php, line 12

Namespace

Drupal\Tests\scheduled_transitions\Traits
View source
trait ScheduledTransitionTestTrait {

  /**
   * Enable bundles for use with scheduled transitions.
   *
   * @param array $bundles
   *   Arrays of bundles. Where each bundle is an array containing:
   *    - 0: Entity type ID.
   *    - 1: Bundle ID.
   */
  protected function enabledBundles(array $bundles) : void {
    $enabledBundles = [];
    foreach ($bundles as $bundle) {
      $enabledBundles[] = [
        'entity_type' => $bundle[0],
        'bundle' => $bundle[1],
      ];
    }
    \Drupal::configFactory()
      ->getEditable('scheduled_transitions.settings')
      ->set('bundles', $enabledBundles)
      ->save(TRUE);
  }

  /**
   * Checks and runs any ready transitions.
   *
   * @param \Drupal\scheduled_transitions\Entity\ScheduledTransitionInterface $scheduledTransition
   *   A scheduled transition.
   */
  protected function runTransition(ScheduledTransitionInterface $scheduledTransition) : void {

    /** @var \Drupal\scheduled_transitions\ScheduledTransitionsRunnerInterface $runner */
    $runner = \Drupal::service('scheduled_transitions.runner');
    $runner
      ->runTransition($scheduledTransition);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ScheduledTransitionTestTrait::enabledBundles protected function Enable bundles for use with scheduled transitions.
ScheduledTransitionTestTrait::runTransition protected function Checks and runs any ready transitions.