public function NodeRevisionsUiTest::testNodeRevisionsTabWithDefaultRevision in Drupal 8
Same name and namespace in other branches
- 9 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 133
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
->assertNoLinkByHref('/node/' . $node_id . '/revisions/1/revert');
$elements = $this
->xpath('//tr[contains(@class, "revision-current")]/td/a[1]');
// The site may be installed in a subdirectory, so check if the URL is
// contained in the retrieved one.
$this
->assertStringContainsString('/node/1', current($elements)
->getAttribute('href'));
// Verify that the default revision can be an older revision than the latest
// one.
// Assert that the revisions with translations changes are shown.
$this
->assertLinkByHref('/node/' . $node_id . '/revisions/4/revert');
// Assert that the revisions without translations changes are filtered out:
// 2, 3 and 5.
$this
->assertNoLinkByHref('/node/' . $node_id . '/revisions/2/revert');
$this
->assertNoLinkByHref('/node/' . $node_id . '/revisions/3/revert');
$this
->assertNoLinkByHref('/node/' . $node_id . '/revisions/5/revert');
}