You are here

protected function SchedulerRevisioningTest::scheduleAndRunCron in Scheduler 2.x

Simulates the scheduled (un)publication of an entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to schedule.

string $action: The action to perform: either 'publish' or 'unpublish'.

Return value

\Drupal\Core\Entity\EntityInterface The updated entity, after scheduled (un)publication via a cron run.

2 calls to SchedulerRevisioningTest::scheduleAndRunCron()
SchedulerRevisioningTest::testAlterCreationDate in tests/src/Functional/SchedulerRevisioningTest.php
Tests the 'touch' option to alter the created date during publishing.
SchedulerRevisioningTest::testNewRevision in tests/src/Functional/SchedulerRevisioningTest.php
Tests the creation of new revisions on scheduling.

File

tests/src/Functional/SchedulerRevisioningTest.php, line 25

Class

SchedulerRevisioningTest
Tests revision options when Scheduler publishes or unpublishes content.

Namespace

Drupal\Tests\scheduler\Functional

Code

protected function scheduleAndRunCron(EntityInterface $entity, string $action) {

  // Simulate scheduling by setting the (un)publication date in the past and
  // running cron.
  $entity->{$action . '_on'} = strtotime('-5 hour', $this->requestTime);
  $entity
    ->save();
  scheduler_cron();
  $storage = $this
    ->entityStorageObject($entity
    ->getEntityTypeId());
  $storage
    ->resetCache([
    $entity
      ->id(),
  ]);
  return $storage
    ->load($entity
    ->id());
}