You are here

public function SchedulerRevisioningTest::testAlterCreationDate in Scheduler 2.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/SchedulerRevisioningTest.php \Drupal\Tests\scheduler\Functional\SchedulerRevisioningTest::testAlterCreationDate()

Tests the 'touch' option to alter the created date during publishing.

@dataProvider dataStandardEntityTypes()

File

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

Class

SchedulerRevisioningTest
Tests revision options when Scheduler publishes or unpublishes content.

Namespace

Drupal\Tests\scheduler\Functional

Code

public function testAlterCreationDate($entityTypeId, $bundle) {

  // Ensure entities with past dates are scheduled not published immediately.
  $entityType = $this
    ->entityTypeObject($entityTypeId, $bundle);
  $entityType
    ->setThirdPartySetting('scheduler', 'publish_past_date', 'schedule')
    ->save();

  // Create an entity with a 'created' date two days in the past.
  $created = strtotime('-2 day', $this->requestTime);
  $settings = [
    'created' => $created,
    'status' => FALSE,
  ];
  $entity = $this
    ->createEntity($entityTypeId, $bundle, $settings);

  // Show that the entity is not published.
  $this
    ->assertFalse($entity
    ->isPublished(), 'The entity is not published.');

  // Schedule the entity for publishing and run cron.
  $entity = $this
    ->scheduleAndRunCron($entity, 'publish');

  // Get the created date from the entity and check that it has not changed.
  $created_after_cron = $entity->created->value;
  $this
    ->assertTrue($entity
    ->isPublished(), 'The entity has been published.');
  $this
    ->assertEquals($created, $created_after_cron, 'The entity creation date is not changed by default.');

  // Set option to change the created date to match the publish_on date.
  $entityType
    ->setThirdPartySetting('scheduler', 'publish_touch', TRUE)
    ->save();

  // Schedule the entity again and run cron.
  $entity = $this
    ->scheduleAndRunCron($entity, 'publish');

  // Check that the created date has changed to match the publish_on date.
  $created_after_cron = $entity->created->value;
  $this
    ->assertEquals(strtotime('-5 hour', $this->requestTime), $created_after_cron, "With 'touch' option set, the entity creation date is changed to match the publishing date.");
}