Unverified Commit 4ba0a5e9 authored by Alex Pott's avatar Alex Pott
Browse files

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

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

This reverts commit 6f7ea6cf.
parent 6f7ea6cf
Loading
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -163,7 +163,10 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
   *   The prepared revision ready to be stored.
   */
  protected function prepareRevertedRevision(NodeInterface $revision, FormStateInterface $form_state) {
    return $this->nodeStorage->createRevision($revision);
    $revision->setNewRevision();
    $revision->isDefaultRevision(TRUE);

    return $revision;
  }

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

  /**
@@ -475,38 +473,4 @@ 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);
  }

}