You are here

public function SchedulerRevisioningTest::testRevisioning in Scheduler 8

Tests the creation of new revisions on scheduling.

File

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

Class

SchedulerRevisioningTest
Tests revision options when Scheduler publishes or unpublishes content.

Namespace

Drupal\Tests\scheduler\Functional

Code

public function testRevisioning() {

  // Create a scheduled node that is not automatically revisioned.
  $created = strtotime('-2 day', $this->requestTime);
  $settings = [
    'type' => $this->type,
    'revision' => 0,
    'created' => $created,
  ];
  $node = $this
    ->drupalCreateNode($settings);

  // Ensure nodes with past dates will be scheduled not published immediately.
  $this->nodetype
    ->setThirdPartySetting('scheduler', 'publish_past_date', 'schedule')
    ->save();

  // First test scheduled publication with revisioning disabled by default.
  $node = $this
    ->schedule($node);
  $this
    ->assertRevisionCount($node
    ->id(), 1, 'No new revision is created by default when a node is published.');

  // Test scheduled unpublication.
  $node = $this
    ->schedule($node, 'unpublish');
  $this
    ->assertRevisionCount($node
    ->id(), 1, 'No new revision is created by default when a node is unpublished.');

  // Enable revisioning.
  $this->nodetype
    ->setThirdPartySetting('scheduler', 'publish_revision', TRUE)
    ->setThirdPartySetting('scheduler', 'unpublish_revision', TRUE)
    ->save();

  // Test scheduled publication with revisioning enabled.
  $node = $this
    ->schedule($node);
  $this
    ->assertRevisionCount($node
    ->id(), 2, 'A new revision was created when revisioning is enabled.');
  $expected_message = sprintf('Published by Scheduler. The scheduled publishing date was %s.', $this->dateFormatter
    ->format(strtotime('-5 hour', $this->requestTime), 'short'));
  $this
    ->assertRevisionLogMessage($node
    ->id(), $expected_message, 'The correct message was found in the node revision log after scheduled publishing.');

  // Test scheduled unpublication with revisioning enabled.
  $node = $this
    ->schedule($node, 'unpublish');
  $this
    ->assertRevisionCount($node
    ->id(), 3, 'A new revision was created when a node was unpublished with revisioning enabled.');
  $expected_message = sprintf('Unpublished by Scheduler. The scheduled unpublishing date was %s.', $this->dateFormatter
    ->format(strtotime('-5 hour', $this->requestTime), 'short'));
  $this
    ->assertRevisionLogMessage($node
    ->id(), $expected_message, 'The correct message was found in the node revision log after scheduled unpublishing.');
}