diff --git a/core/modules/node/src/Tests/Views/RevisionLinkTest.php b/core/modules/node/src/Tests/Views/RevisionLinkTest.php new file mode 100644 index 0000000..37e52ac --- /dev/null +++ b/core/modules/node/src/Tests/Views/RevisionLinkTest.php @@ -0,0 +1,101 @@ +drupalCreateContentType(array('name' => 'page', 'type' => 'page')); + $account = $this->drupalCreateUser(array('revert all revisions', 'view all revisions', 'delete all revisions', 'edit any page content', 'delete any page content')); + $this->drupalLogin($account); + // Create two nodes, one without an additional revision and one with a + // revision. + $node = $this->drupalCreateNode(); + $this->nodes[] = $node; + $node = $this->drupalCreateNode(); + $this->nodes[] = $node; + + $first_revision = $node->getRevisionId(); + // Create revision of the node. + $node->setNewRevision(); + $node->save(); + $second_revision = $node->getRevisionId(); + + $this->drupalGet('test-node-revision-links'); + $this->assertResponse(200, 'Test view can be accessed in the path expected'); + // The first node revision should link to the node directly as you get an + // access denied if you link to the revision. + $url = $this->nodes[0]->urlInfo()->toString(); + $this->assertLinkByHref($url); + $this->assertNoLinkByHref($url . '/revisions/' . $this->nodes[0]->getRevisionId() . '/delete'); + $this->assertNoLinkByHref($url . '/revisions/' . $this->nodes[0]->getRevisionId() . '/revert'); + + // For the second node the current revision got set to the last revision, so + // the first one should also link to the node page itself. + $url = $this->nodes[1]->urlInfo()->toString(); + $this->assertLinkByHref($url . '/revisions/' . $first_revision . '/view'); + $this->assertLinkByHref($url . '/revisions/' . $first_revision . '/delete'); + $this->assertLinkByHref($url . '/revisions/' . $first_revision . '/revert'); + + $this->assertLinkByHref($url); + $this->assertNoLinkByHref($url . '/revisions/' . $second_revision . '/view'); + $this->assertNoLinkByHref($url . '/revisions/' . $second_revision . '/delete'); + $this->assertNoLinkByHref($url . '/revisions/' . $second_revision . '/revert'); + + $accounts = array(); + $accounts['view'] = $this->drupalCreateUser(array('view all revisions')); + $accounts['revert'] = $this->drupalCreateUser(array('revert all revisions', 'edit any page content')); + $accounts['delete'] = $this->drupalCreateUser(array('delete all revisions', 'delete any page content')); + $operations = array_keys($accounts); + array_shift($operations); + $url = $this->nodes[1]->urlInfo()->toString(); + // Render the view with users which can only delete/revert revisions. + foreach ($accounts as $op => $account) { + $this->drupalLogin($account); + $this->drupalGet('test-node-revision-links'); + // Check expected links. + foreach ($operations as $operation) { + if ($operation == $op) { + $this->assertLinkByHref($url . '/revisions/' . $first_revision . '/' . $operation); + } + else { + $this->assertNoLinkByHref($url . '/revisions/' . $first_revision . '/' . $operation); + } + } + } + } + +} diff --git a/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_node_revision_links.yml b/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_node_revision_links.yml new file mode 100644 index 0000000..1313f01 --- /dev/null +++ b/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_node_revision_links.yml @@ -0,0 +1,224 @@ +langcode: en +status: true +dependencies: + module: + - node +id: test_node_revision_links +label: test_node_revision_links +module: views +description: '' +tag: '' +base_table: node_field_revision +base_field: vid +core: '8' +display: + default: + display_plugin: default + id: default + display_title: Master + position: 0 + display_options: + access: + type: none + options: { } + cache: + type: none + options: { } + query: + type: views_query + options: + disable_sql_rewrite: false + distinct: false + replica: false + query_comment: '' + query_tags: { } + exposed_form: + type: basic + options: + submit_button: Apply + reset_button: false + reset_button_label: Reset + exposed_sorts_label: 'Sort by' + expose_sort_order: true + sort_asc_label: Asc + sort_desc_label: Desc + pager: + type: none + options: + items_per_page: 0 + offset: 0 + style: + type: default + row: + type: fields + fields: + link_to_revision: + id: link_to_revision + table: node_field_revision + field: link_to_revision + relationship: none + group_type: group + admin_label: '' + label: '' + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + text: 'Link to revision' + entity_type: node + plugin_id: node_revision_link + delete_revision: + id: delete_revision + table: node_field_revision + field: delete_revision + relationship: none + group_type: group + admin_label: '' + label: '' + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + text: 'Link to delete revision' + entity_type: node + plugin_id: node_revision_link_delete + revert_revision: + id: revert_revision + table: node_field_revision + field: revert_revision + relationship: none + group_type: group + admin_label: '' + label: '' + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + text: 'Link to delete revision' + entity_type: node + plugin_id: node_revision_link_revert + filters: { } + sorts: { } + title: test_node_revision_links + header: { } + footer: { } + empty: { } + relationships: { } + arguments: { } + display_extenders: { } + page_1: + display_plugin: page + id: page_1 + display_title: Page + position: 1 + display_options: + display_extenders: { } + path: test-node-revision-links