You are here

public function ScheduledTransitionTest::testChangedTimeUpdated in Scheduled Transitions 8

Same name and namespace in other branches
  1. 2.x tests/src/Kernel/ScheduledTransitionTest.php \Drupal\Tests\scheduled_transitions\Kernel\ScheduledTransitionTest::testChangedTimeUpdated()

Test the changed timestamp is updated when a transition is executed.

File

tests/src/Kernel/ScheduledTransitionTest.php, line 670

Class

ScheduledTransitionTest
Tests basic functionality of scheduled_transitions fields.

Namespace

Drupal\Tests\scheduled_transitions\Kernel

Code

public function testChangedTimeUpdated() {
  $workflow = $this
    ->createEditorialWorkflow();
  $workflow
    ->getTypePlugin()
    ->addEntityTypeAndBundle('st_entity_test', 'st_entity_test');
  $workflow
    ->save();

  /** @var \Drupal\Core\Entity\TranslatableRevisionableStorageInterface $entityStorage */
  $entityStorage = \Drupal::entityTypeManager()
    ->getStorage('st_entity_test');
  $entity = TestEntity::create([
    'type' => 'st_entity_test',
  ]);
  $entity = $entityStorage
    ->createRevision($entity, FALSE);
  $entity->name = 'rev1';
  $entity->changed = (new \DateTime('1 year ago'))
    ->getTimestamp();
  $entity->moderation_state = 'draft';
  $entity
    ->save();
  $scheduledTransition = ScheduledTransition::create([
    'entity' => $entity,
    'entity_revision_id' => $entity
      ->getRevisionId(),
    'author' => 1,
    'workflow' => $workflow
      ->id(),
    'moderation_state' => 'published',
    'transition_on' => (new \DateTime('1 year ago'))
      ->getTimestamp(),
  ]);
  $scheduledTransition
    ->save();
  $this
    ->runTransition($scheduledTransition);

  /** @var \Drupal\Component\Datetime\TimeInterface $time */
  $time = \Drupal::service('datetime.time');
  $this
    ->assertEquals($time
    ->getRequestTime(), $entityStorage
    ->load($entity
    ->id())->changed->value);
}