You are here

public function ModeratedContentSchedulingTest::testPublishStateSchedule in Thunder 8.5

Same name and namespace in other branches
  1. 8.3 tests/src/FunctionalJavascript/ModeratedContentSchedulingTest.php \Drupal\Tests\thunder\FunctionalJavascript\ModeratedContentSchedulingTest::testPublishStateSchedule()
  2. 8.4 tests/src/FunctionalJavascript/ModeratedContentSchedulingTest.php \Drupal\Tests\thunder\FunctionalJavascript\ModeratedContentSchedulingTest::testPublishStateSchedule()
  3. 6.2.x tests/src/FunctionalJavascript/ModeratedContentSchedulingTest.php \Drupal\Tests\thunder\FunctionalJavascript\ModeratedContentSchedulingTest::testPublishStateSchedule()
  4. 6.0.x tests/src/FunctionalJavascript/ModeratedContentSchedulingTest.php \Drupal\Tests\thunder\FunctionalJavascript\ModeratedContentSchedulingTest::testPublishStateSchedule()
  5. 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\FunctionalJavascript

Code

public function testPublishStateSchedule() {
  $publish_timestamp = strtotime('yesterday');

  /** @var \Drupal\node\NodeStorageInterface $node_storage */
  $node_storage = \Drupal::entityTypeManager()
    ->getStorage('node');
  $this
    ->articleFillNew([
    'field_channel' => 1,
    '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 $node \Drupal\node\Entity\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();
  $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(),
  ]);
  $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();
  $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());
}