public function NodeRevisionsUiTest::testNodeRevisionsTabWithDefaultRevision in Drupal 9
Same name and namespace in other branches
- 8 core/modules/node/tests/src/Functional/NodeRevisionsUiTest.php \Drupal\Tests\node\Functional\NodeRevisionsUiTest::testNodeRevisionsTabWithDefaultRevision()
Checks the Revisions tab.
File
- core/
modules/ node/ tests/ src/ Functional/ NodeRevisionsUiTest.php, line 135
Class
- NodeRevisionsUiTest
- Tests the UI for controlling node revision behavior.
Namespace
Drupal\Tests\node\FunctionalCode
public function testNodeRevisionsTabWithDefaultRevision() {
$this
->drupalLogin($this->editor);
// Create the node.
$node = $this
->drupalCreateNode();
$storage = \Drupal::entityTypeManager()
->getStorage($node
->getEntityTypeId());
// Create a new revision based on the default revision.
// Revision 2.
$node = $storage
->load($node
->id());
$node
->setNewRevision(TRUE);
$node
->save();
// Revision 3.
$node = $storage
->load($node
->id());
$node
->setNewRevision(TRUE);
$node
->save();
// Revision 4.
// Trigger translation changes in order to show the revision.
$node = $storage
->load($node
->id());
$node
->setTitle($this
->randomString());
$node
->isDefaultRevision(FALSE);
$node
->setNewRevision(TRUE);
$node
->save();
// Revision 5.
$node = $storage
->load($node
->id());
$node
->isDefaultRevision(FALSE);
$node
->setNewRevision(TRUE);
$node
->save();
$node_id = $node
->id();
$this
->drupalGet('node/' . $node_id . '/revisions');
// Verify that the latest affected revision having been a default revision
// is displayed as the current one.
$this
->assertSession()
->linkByHrefNotExists('/node/' . $node_id . '/revisions/1/revert');
// The site may be installed in a subdirectory, so check if the URL is
// contained in the retrieved one.
$this
->assertSession()
->elementAttributeContains('xpath', '//tr[contains(@class, "revision-current")]/td/a[1]', 'href', '/node/1');
// Verify that the default revision can be an older revision than the latest
// one.
// Assert that the revisions with translations changes are shown.
$this
->assertSession()
->linkByHrefExists('/node/' . $node_id . '/revisions/4/revert');
// Assert that the revisions without translations changes are filtered out:
// 2, 3 and 5.
$this
->assertSession()
->linkByHrefNotExists('/node/' . $node_id . '/revisions/2/revert');
$this
->assertSession()
->linkByHrefNotExists('/node/' . $node_id . '/revisions/3/revert');
$this
->assertSession()
->linkByHrefNotExists('/node/' . $node_id . '/revisions/5/revert');
}