You are here

public function ModeratedContentSchedulingTest::testUnpublishStateSchedule in Scheduler content moderation integration 8

Tests moderated nodes unpublish scheduling.

File

tests/src/Kernel/ModeratedContentSchedulingTest.php, line 64

Class

ModeratedContentSchedulingTest
Tests publishing/unpublishing scheduling for moderated nodes.

Namespace

Drupal\Tests\scheduler_content_moderation_integration\Kernel

Code

public function testUnpublishStateSchedule() {
  $node = Node::create([
    'type' => 'example',
    'title' => 'Published title',
    'moderation_state' => 'published',
    'unpublish_on' => strtotime('yesterday'),
    'unpublish_state' => 'archived',
  ]);
  $node
    ->save();
  $revision_id = $node
    ->getRevisionId();

  // Make sure node is published.
  $this
    ->assertEquals(TRUE, Node::load($node
    ->id())
    ->isPublished());
  $this->container
    ->get('cron')
    ->run();

  // Assert node is now unpublished.
  $this
    ->assertEquals(FALSE, Node::load($node
    ->id())
    ->isPublished());

  // Assert only one revision is created during the operation.
  $this
    ->assertEquals($revision_id + 1, Node::load($node
    ->id())
    ->getRevisionId());
}