public function ModeratedContentSchedulingTest::testPublishStateSchedule in Thunder 6.2.x
Same name and namespace in other branches
- 8.5 tests/src/FunctionalJavascript/ModeratedContentSchedulingTest.php \Drupal\Tests\thunder\FunctionalJavascript\ModeratedContentSchedulingTest::testPublishStateSchedule()
- 8.3 tests/src/FunctionalJavascript/ModeratedContentSchedulingTest.php \Drupal\Tests\thunder\FunctionalJavascript\ModeratedContentSchedulingTest::testPublishStateSchedule()
- 8.4 tests/src/FunctionalJavascript/ModeratedContentSchedulingTest.php \Drupal\Tests\thunder\FunctionalJavascript\ModeratedContentSchedulingTest::testPublishStateSchedule()
- 6.0.x tests/src/FunctionalJavascript/ModeratedContentSchedulingTest.php \Drupal\Tests\thunder\FunctionalJavascript\ModeratedContentSchedulingTest::testPublishStateSchedule()
- 6.1.x tests/src/FunctionalJavascript/ModeratedContentSchedulingTest.php \Drupal\Tests\thunder\FunctionalJavascript\ModeratedContentSchedulingTest::testPublishStateSchedule()
Tests moderated nodes publish scheduling.
File
- tests/
src/ FunctionalJavascript/ ModeratedContentSchedulingTest.php, line 19
Class
- ModeratedContentSchedulingTest
- Tests publishing/unpublishing scheduling for moderated nodes.
Namespace
Drupal\Tests\thunder\FunctionalJavascriptCode
public function testPublishStateSchedule() {
$publish_timestamp = strtotime('yesterday');
/** @var \Drupal\node\NodeStorageInterface $node_storage */
$node_storage = \Drupal::entityTypeManager()
->getStorage('node');
$term = $this
->loadTermByUuid('bfc251bc-de35-467d-af44-1f7a7012b845');
$this
->articleFillNew([
'field_channel' => $term
->id(),
'title[0][value]' => 'Test workflow article 1 - Published',
'field_seo_title[0][value]' => 'Massive gaining seo traffic text 1',
'moderation_state[0]' => 'draft',
'publish_on[0][value][date]' => date('Y-m-d', $publish_timestamp),
'publish_on[0][value][time]' => date('H:i:s', $publish_timestamp),
'publish_state[0]' => 'published',
]);
$this
->clickSave();
/** @var \Drupal\node\Entity\Node $node */
$node = $this
->getNodeByTitle('Test workflow article 1 - Published');
$revision_id = $node
->getRevisionId();
// Make sure node is unpublished.
$this
->assertEquals(FALSE, Node::load($node
->id())
->isPublished());
$this->container
->get('cron')
->run();
/** @var \Drupal\node\Entity\Node $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());
$edit_url = $node
->toUrl('edit-form');
$this
->drupalGet($edit_url);
$this
->expandAllTabs();
$this
->setFieldValues($this
->getSession()
->getPage(), [
'title[0][value]' => 'Test workflow article 1 - Draft',
'moderation_state[0]' => 'draft',
'publish_on[0][value][date]' => date('Y-m-d', $publish_timestamp),
'publish_on[0][value][time]' => date('H:i:s', $publish_timestamp),
'publish_state[0]' => 'published',
]);
$this
->clickSave();
$node_storage
->resetCache([
$node
->id(),
]);
/** @var \Drupal\node\Entity\Node $node */
$node = $node_storage
->loadRevision($node_storage
->getLatestRevisionId($node
->id()));
$this
->assertEquals('Test workflow article 1 - Draft', $node
->getTitle());
$this
->assertEquals('draft', $node->moderation_state->value);
$this->container
->get('cron')
->run();
/** @var \Drupal\node\Entity\Node $node */
$node = $node_storage
->loadRevision($node_storage
->getLatestRevisionId($node
->id()));
$this
->assertEquals(TRUE, $node
->isPublished());
$this
->assertEquals('published', $node->moderation_state->value);
$this
->assertEquals('Test workflow article 1 - Draft', $node
->getTitle());
}