Unverified Commit 6f7ea6cf authored by Alex Pott's avatar Alex Pott
Browse files

feat: #3535230 Reverted revision is not listed on the version history when...

feat: #3535230 Reverted revision is not listed on the version history when using Set as current revision

By: idebr
By: acbramley
By: berdir
By: alexpottCopy Code
(cherry picked from commit c8010dd3)
parent 35a0de45
Loading
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -163,10 +163,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
   *   The prepared revision ready to be stored.
   */
  protected function prepareRevertedRevision(NodeInterface $revision, FormStateInterface $form_state) {
    $revision->setNewRevision();
    $revision->isDefaultRevision(TRUE);

    return $revision;
    return $this->nodeStorage->createRevision($revision);
  }

}
+37 −1
Original line number Diff line number Diff line
@@ -453,7 +453,9 @@ public function testRevisionTranslationRevert(): void {
    $node = $node_storage->load($node->id());
    $this->assertGreaterThan($latest_revision_id, $node->getRevisionId());
    $this->assertEquals($initial_title, $node->label());
    $this->assertFalse($node->hasTranslation('it'));
    // The node should retain the translations from the last default revision.
    // @see \Drupal\Core\Entity\ContentEntityStorageBase::createRevision.
    $this->assertTrue($node->hasTranslation('it'));
  }

  /**
@@ -473,4 +475,38 @@ protected function createRevisions(NodeInterface $node, $count): void {
    }
  }

  /**
   * Tests the Set as current revision link.
   *
   * This operation appears on the revision list when there is a more recent
   * revision than the current revision.
   */
  public function testSetAsCurrentRevision(): void {
    $node = $this->drupalCreateNode();
    // Create a non-default revision.
    $node->setNewRevision();
    $node->isDefaultRevision(FALSE);
    $node->body->value = '<p>new body</p>';
    $node->setRevisionLogMessage('non default revision message');
    $node->save();

    $this->drupalGet($node->toUrl('version-history'));
    $this->assertSession()->linkExists('Set as current revision');
    $this->clickLink('Set as current revision');
    $this->submitForm([], 'Revert');

    $this->assertSession()->pageTextContains(sprintf('Basic page %s has been reverted', $node->label()));

    // Reverting the non-default revision should create a new revision and set
    // it as the default, meaning there should be 3 revisions displayed and no
    // Set as current revision link.
    $this->assertSession()->elementsCount('css', '.node-revision-table tbody tr', 3);
    $this->assertSession()->linkNotExists('Set as current revision');
    $this->assertSession()->pageTextContains('Copy of the revision from');
    // The first row (the revision we just reverted to) should be displayed as
    // the current revision.
    $firstRowSecondColumnText = $this->getSession()->getPage()->find('xpath', '//tbody/tr[1]/td[2]/em')->getText();
    $this->assertEquals('Current revision', $firstRowSecondColumnText);
  }

}