function NodeRevisionsTest::testSetAsCurrentRevision

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.

File

core/modules/node/tests/src/Functional/NodeRevisionsTest.php, line 484

Class

NodeRevisionsTest
Tests per-content-type node CRUD operation permissions.

Namespace

Drupal\Tests\node\Functional

Code

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);
}

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