You are here

public function ScheduledTransitionTest::testChangedTimeUpdated in Scheduled Transitions 2.x

Same name and namespace in other branches
  1. 8 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 669

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::createFrom($workflow, 'published', $entity, new \DateTime('1 year ago'), new UserSession([
    'uid' => 1,
  ]));
  $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);
}