function ModerationRevisionRevertTest::testEditingAfterRevertRevision

Same name in other branches
  1. 8.9.x core/modules/content_moderation/tests/src/Functional/ModerationRevisionRevertTest.php \Drupal\Tests\content_moderation\Functional\ModerationRevisionRevertTest::testEditingAfterRevertRevision()
  2. 10 core/modules/content_moderation/tests/src/Functional/ModerationRevisionRevertTest.php \Drupal\Tests\content_moderation\Functional\ModerationRevisionRevertTest::testEditingAfterRevertRevision()
  3. 11.x core/modules/content_moderation/tests/src/Functional/ModerationRevisionRevertTest.php \Drupal\Tests\content_moderation\Functional\ModerationRevisionRevertTest::testEditingAfterRevertRevision()

Tests that reverting a revision works.

File

core/modules/content_moderation/tests/src/Functional/ModerationRevisionRevertTest.php, line 65

Class

ModerationRevisionRevertTest
Test revision revert.

Namespace

Drupal\Tests\content_moderation\Functional

Code

public function testEditingAfterRevertRevision() {
    // Create a draft.
    $this->drupalGet('node/add/moderated_bundle');
    $this->submitForm([
        'title[0][value]' => 'First draft node',
        'moderation_state[0][state]' => 'draft',
    ], 'Save');
    // Now make it published.
    $this->drupalGet('node/1/edit');
    $this->submitForm([
        'title[0][value]' => 'Published node',
        'moderation_state[0][state]' => 'published',
    ], 'Save');
    // Check the editing form that show the published title.
    $this->drupalGet('node/1/edit');
    $this->assertSession()
        ->pageTextContains('Published node');
    // Revert the first revision.
    $revision_url = 'node/1/revisions/1/revert';
    $this->drupalGet($revision_url);
    $this->assertSession()
        ->elementExists('css', '.form-submit');
    $this->click('.form-submit');
    // Check that it reverted.
    $this->drupalGet('node/1/edit');
    $this->assertSession()
        ->pageTextContains('First draft node');
    // Try to save the node.
    $this->drupalGet('node/1/edit');
    $this->submitForm([
        'moderation_state[0][state]' => 'draft',
    ], 'Save');
    // Check if the submission passed the EntityChangedConstraintValidator.
    $this->assertSession()
        ->pageTextNotContains('The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved.');
    // Check the node has been saved.
    $this->assertSession()
        ->pageTextContains('moderated_bundle First draft node has been updated');
}

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