function ModerationStateNodeTest::testFormSaveDestination

Same name and namespace in other branches
  1. 8.9.x core/modules/content_moderation/tests/src/Functional/ModerationStateNodeTest.php \Drupal\Tests\content_moderation\Functional\ModerationStateNodeTest::testFormSaveDestination()
  2. 10 core/modules/content_moderation/tests/src/Functional/ModerationStateNodeTest.php \Drupal\Tests\content_moderation\Functional\ModerationStateNodeTest::testFormSaveDestination()
  3. 11.x 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 86

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->drupalGet('node/add/moderated_content');
    $this->submitForm([
        'title[0][value]' => 'Some moderated content',
        'body[0][value]' => 'First version of the content.',
        'moderation_state[0][state]' => 'draft',
    ], '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->assertSession()
        ->addressEquals(Url::fromRoute('entity.node.canonical', [
        'node' => $node->id(),
    ]));
    $this->assertSession()
        ->pageTextContains('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->drupalGet($edit_path);
    $this->submitForm([
        'body[0][value]' => 'Second version of the content.',
        'moderation_state[0][state]' => 'draft',
    ], 'Save');
    $this->assertSession()
        ->addressEquals(Url::fromRoute('entity.node.canonical', [
        'node' => $node->id(),
    ]));
    $this->assertSession()
        ->pageTextContains('Second version of the content.');
    // Make a new published revision; after saving, we should be at the
    // canonical URL.
    $this->drupalGet($edit_path);
    $this->submitForm([
        'body[0][value]' => 'Third version of the content.',
        'moderation_state[0][state]' => 'published',
    ], 'Save');
    $this->assertSession()
        ->addressEquals(Url::fromRoute('entity.node.canonical', [
        'node' => $node->id(),
    ]));
    $this->assertSession()
        ->pageTextContains('Third version of the content.');
    // Make a new pending revision; after saving, we should be on the "Latest
    // version" tab.
    $this->drupalGet($edit_path);
    $this->submitForm([
        'body[0][value]' => 'Fourth version of the content.',
        'moderation_state[0][state]' => 'draft',
    ], 'Save');
    $this->assertSession()
        ->addressEquals(Url::fromRoute('entity.node.latest_version', [
        'node' => $node->id(),
    ]));
    $this->assertSession()
        ->pageTextContains('Fourth version of the content.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.