3 namespace Drupal\Tests\node\Functional\Views;
6 * Tests the different revision link handlers.
10 * @see \Drupal\node\Plugin\views\field\RevisionLink
11 * @see \Drupal\node\Plugin\views\field\RevisionLinkDelete
12 * @see \Drupal\node\Plugin\views\field\RevisionLinkRevert
14 class RevisionLinkTest extends NodeTestBase {
17 * Views used by this test.
21 public static $testViews = ['test_node_revision_links'];
24 * Tests revision links.
26 public function testRevisionLinks() {
27 // Create one user which can view/revert and delete and one which can only
29 $this->drupalCreateContentType(['name' => 'page', 'type' => 'page']);
30 $account = $this->drupalCreateUser(['revert all revisions', 'view all revisions', 'delete all revisions', 'edit any page content', 'delete any page content']);
31 $this->drupalLogin($account);
32 // Create two nodes, one without an additional revision and one with a
35 $this->drupalCreateNode(),
36 $this->drupalCreateNode(),
39 $first_revision = $nodes[1]->getRevisionId();
40 // Create revision of the node.
41 $nodes[1]->setNewRevision();
43 $second_revision = $nodes[1]->getRevisionId();
45 $this->drupalGet('test-node-revision-links');
46 $this->assertResponse(200, 'Test view can be accessed in the path expected');
47 // The first node revision should link to the node directly as you get an
48 // access denied if you link to the revision.
49 $url = $nodes[0]->urlInfo()->toString();
50 $this->assertLinkByHref($url);
51 $this->assertNoLinkByHref($url . '/revisions/' . $nodes[0]->getRevisionId() . '/view');
52 $this->assertNoLinkByHref($url . '/revisions/' . $nodes[0]->getRevisionId() . '/delete');
53 $this->assertNoLinkByHref($url . '/revisions/' . $nodes[0]->getRevisionId() . '/revert');
55 // For the second node the current revision got set to the last revision, so
56 // the first one should also link to the node page itself.
57 $url = $nodes[1]->urlInfo()->toString();
58 $this->assertLinkByHref($url);
59 $this->assertLinkByHref($url . '/revisions/' . $first_revision . '/view');
60 $this->assertLinkByHref($url . '/revisions/' . $first_revision . '/delete');
61 $this->assertLinkByHref($url . '/revisions/' . $first_revision . '/revert');
62 $this->assertNoLinkByHref($url . '/revisions/' . $second_revision . '/view');
63 $this->assertNoLinkByHref($url . '/revisions/' . $second_revision . '/delete');
64 $this->assertNoLinkByHref($url . '/revisions/' . $second_revision . '/revert');
67 'view' => $this->drupalCreateUser(['view all revisions']),
68 'revert' => $this->drupalCreateUser(['revert all revisions', 'edit any page content']),
69 'delete' => $this->drupalCreateUser(['delete all revisions', 'delete any page content']),
72 $url = $nodes[1]->urlInfo()->toString();
73 // Render the view with users which can only delete/revert revisions.
74 foreach ($accounts as $allowed_operation => $account) {
75 $this->drupalLogin($account);
76 $this->drupalGet('test-node-revision-links');
77 // Check expected links.
78 foreach (['revert', 'delete'] as $operation) {
79 if ($operation == $allowed_operation) {
80 $this->assertLinkByHref($url . '/revisions/' . $first_revision . '/' . $operation);
83 $this->assertNoLinkByHref($url . '/revisions/' . $first_revision . '/' . $operation);