diff --git a/core/modules/node/lib/Drupal/node/Tests/Views/RevisionLinkTest.php b/core/modules/node/lib/Drupal/node/Tests/Views/RevisionLinkTest.php new file mode 100644 index 0000000..177d0bc --- /dev/null +++ b/core/modules/node/lib/Drupal/node/Tests/Views/RevisionLinkTest.php @@ -0,0 +1,106 @@ + 'Node: Revision Links', + 'description' => 'Tests the different revision link handlers.', + 'group' => 'Views module integration', + ); + } + + /** + * Tests revision links. + */ + public function testRevisionLinks() { + // Create one user which can view/revert and delete and one which can only + // do one of them. + $this->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. + $this->nodes[] = $node = $this->drupalCreateNode(); + $this->revisions[] = $node; + + $this->nodes[] = $node = $this->drupalCreateNode(); + $this->revisions[] = $node; + $node = clone $node; + $node->setNewRevision(); + $this->revisions[] = $node; + $node->save(); + + $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. + $path = $this->nodes[0]->getSystemPath(); + $this->assertLinkByHref($path); + $this->assertNoLinkByHref($path . '/revisions/' . $this->revisions[0]->getRevisionId() . '/delete'); + $this->assertNoLinkByHref($path . '/revision/' . $this->revisions[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. + $path = $this->revisions[1]->getSystemPath(); + $this->assertLinkByHref($path . '/revisions/' . $this->revisions[1]->getRevisionId() . '/view'); + $this->assertLinkByHref($path . '/revisions/' . $this->revisions[1]->getRevisionId() . '/delete'); + $this->assertLinkByHref($path . '/revisions/' . $this->revisions[1]->getRevisionId() . '/revert'); + + $path = $this->revisions[2]->getSystemPath(); + $this->assertLinkByHref($path); + $this->assertNoLinkByHref($path . '/revisions/' . $this->revisions[2]->getRevisionId() . '/delete'); + $this->assertNoLinkByHref($path . '/revisions/' . $this->revisions[2]->getRevisionId() . '/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); + $path = $this->revisions[1]->getSystemPath(); + // 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($path . '/revisions/' . $this->revisions[1]->getRevisionId() . '/' . $operation); + } + else { + $this->assertNoLinkByHref($path . '/revisions/' . $this->revisions[1]->getRevisionId() . '/' . $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..4c361d9 --- /dev/null +++ b/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_node_revision_links.yml @@ -0,0 +1,223 @@ +langcode: und +status: true +dependencies: + module: + - node +id: test_node_revision_links +label: test_node_revision_links +module: views +description: '' +tag: '' +base_field: vid +base_table: node_field_revision +core: '8' +description: '' +display: + default: + display_plugin: default + id: default + display_title: Master + position: 1 + display_options: + cache: + type: none + options: { } + query: + type: views_query + options: + disable_sql_rewrite: false + distinct: 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_revision + field: link_to_revision + relationship: none + group_type: group + admin_label: '' + label: 'Link to revision' + 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: 1 + 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: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + text: '' + plugin_id: node_revision_link + delete_revision: + id: delete_revision + table: node_revision + field: delete_revision + relationship: none + group_type: group + admin_label: '' + label: 'Link to delete revision' + 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: 1 + 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: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + text: '' + plugin_id: node_revision_link_delete + revert_revision: + id: revert_revision + table: node_revision + field: revert_revision + relationship: none + group_type: group + admin_label: '' + label: 'Link to revert revision' + 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: 1 + 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: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + text: '' + plugin_id: node_revision_link_revert + filters: + status: + table: node_revision + field: status + id: status + expose: + operator: '0' + group: 1 + sorts: { } + title: test_node_revision_links + header: { } + footer: { } + empty: { } + relationships: { } + arguments: { } + page_1: + display_plugin: page + id: page_1 + display_title: Page + position: 1 + display_options: + path: test-node-revision-links