public function ModeratedContentSchedulingTest::testPublishOfDraft in Thunder 8.2
Tests publish scheduling for a draft of a published node.
File
- tests/
src/ Kernel/ ModeratedContentSchedulingTest.php, line 90
Class
- ModeratedContentSchedulingTest
- Tests publishing/unpublishing scheduling for moderated nodes.
Namespace
Drupal\Tests\thunder\KernelCode
public function testPublishOfDraft() {
$node = Node::create([
'type' => 'example',
'title' => 'Published title',
'moderation_state' => 'published',
]);
$node
->save();
$nid = $node
->id();
// Assert node is published.
$this
->assertEquals('Published title', Node::load($nid)
->getTitle());
// Create a new pending revision and validate it's not the deault published
// one.
$node
->setTitle('Draft title');
$node
->set('publish_on', strtotime('yesterday'));
$node
->set('moderation_state', 'draft');
$node
->set('publish_state', 'published');
$node
->save();
$revision_id = $node
->getRevisionId();
// Test latest revision is not the published one.
$this
->assertEquals('Published title', Node::load($nid)
->getTitle());
$this->container
->get('cron')
->run();
// Test latest revision is now the published one.
$this
->assertEquals('Draft title', Node::load($nid)
->getTitle());
// Assert only one revision is created during the operation.
$this
->assertEquals($revision_id + 1, Node::load($node
->id())
->getRevisionId());
}