public function ModeratedContentSchedulingTest::testPublishStateSchedule in Scheduler content moderation integration 8
Tests moderated nodes publish scheduling.
File
- tests/
src/ Kernel/ ModeratedContentSchedulingTest.php, line 17
Class
- ModeratedContentSchedulingTest
- Tests publishing/unpublishing scheduling for moderated nodes.
Namespace
Drupal\Tests\scheduler_content_moderation_integration\KernelCode
public function testPublishStateSchedule() {
$node = Node::create([
'type' => 'example',
'title' => 'Published title',
'moderation_state' => 'draft',
'publish_on' => strtotime('yesterday'),
'publish_state' => 'published',
]);
$node
->save();
$revision_id = $node
->getRevisionId();
// Make sure node is unpublished.
$this
->assertEquals(FALSE, Node::load($node
->id())
->isPublished());
$this->container
->get('cron')
->run();
$node_storage = \Drupal::service('entity_type.manager')
->getStorage('node');
$node = $node_storage
->loadRevision($node_storage
->getLatestRevisionId($node
->id()));
// Assert node is now published.
$this
->assertEquals(TRUE, $node
->isPublished());
$this
->assertEquals('published', $node->moderation_state->value);
// Assert only one revision is created during the operation.
$this
->assertEquals($revision_id + 1, $node
->getRevisionId());
$node
->setTitle('Draft title');
$node->moderation_state->value = 'draft';
$node->publish_on->value = strtotime('yesterday');
$node->publish_state->value = 'published';
$node
->save();
$node = $node_storage
->loadRevision($node_storage
->getLatestRevisionId($node
->id()));
$this
->assertEquals('Draft title', $node
->getTitle());
$this
->assertEquals('draft', $node->moderation_state->value);
$this->container
->get('cron')
->run();
$node = $node_storage
->loadRevision($node_storage
->getLatestRevisionId($node
->id()));
$this
->assertEquals(TRUE, $node
->isPublished());
$this
->assertEquals('published', $node->moderation_state->value);
$this
->assertEquals('Draft title', $node
->getTitle());
}