You are here

public function ModerationStateNodeTest::testFormSaveDestination in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/content_moderation/tests/src/Functional/ModerationStateNodeTest.php \Drupal\Tests\content_moderation\Functional\ModerationStateNodeTest::testFormSaveDestination()

Tests edit form destinations.

File

core/modules/content_moderation/tests/src/Functional/ModerationStateNodeTest.php, line 85

Class

ModerationStateNodeTest
Tests general content moderation workflow for nodes.

Namespace

Drupal\Tests\content_moderation\Functional

Code

public function testFormSaveDestination() {

  // Create new moderated content in draft.
  $this
    ->drupalPostForm('node/add/moderated_content', [
    'title[0][value]' => 'Some moderated content',
    'body[0][value]' => 'First version of the content.',
    'moderation_state[0][state]' => 'draft',
  ], t('Save'));
  $node = $this
    ->drupalGetNodeByTitle('Some moderated content');
  $edit_path = sprintf('node/%d/edit', $node
    ->id());

  // After saving, we should be at the canonical URL and viewing the first
  // revision.
  $this
    ->assertUrl(Url::fromRoute('entity.node.canonical', [
    'node' => $node
      ->id(),
  ]));
  $this
    ->assertText('First version of the content.');

  // Create a new draft; after saving, we should still be on the canonical
  // URL, but viewing the second revision.
  $this
    ->drupalPostForm($edit_path, [
    'body[0][value]' => 'Second version of the content.',
    'moderation_state[0][state]' => 'draft',
  ], t('Save'));
  $this
    ->assertUrl(Url::fromRoute('entity.node.canonical', [
    'node' => $node
      ->id(),
  ]));
  $this
    ->assertText('Second version of the content.');

  // Make a new published revision; after saving, we should be at the
  // canonical URL.
  $this
    ->drupalPostForm($edit_path, [
    'body[0][value]' => 'Third version of the content.',
    'moderation_state[0][state]' => 'published',
  ], t('Save'));
  $this
    ->assertUrl(Url::fromRoute('entity.node.canonical', [
    'node' => $node
      ->id(),
  ]));
  $this
    ->assertText('Third version of the content.');

  // Make a new pending revision; after saving, we should be on the "Latest
  // version" tab.
  $this
    ->drupalPostForm($edit_path, [
    'body[0][value]' => 'Fourth version of the content.',
    'moderation_state[0][state]' => 'draft',
  ], t('Save'));
  $this
    ->assertUrl(Url::fromRoute('entity.node.latest_version', [
    'node' => $node
      ->id(),
  ]));
  $this
    ->assertText('Fourth version of the content.');
}