From fb8335a93594fc1413695f03e4daf5a8fb041f20 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Fri, 14 Apr 2017 07:40:54 +0100 Subject: [PATCH] Issue #2858159 by Artusamak, Lendude: The "User has a revision" views argument handler generates a SQL error --- .../src/Plugin/views/argument/UidRevision.php | 2 +- ...s.view.test_argument_node_uid_revision.yml | 106 ++++++++++++++++++ .../Kernel/Views/ArgumentUidRevisionTest.php | 93 +++++++++++++++ 3 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 core/modules/node/tests/modules/node_test_views/test_views/views.view.test_argument_node_uid_revision.yml create mode 100644 core/modules/node/tests/src/Kernel/Views/ArgumentUidRevisionTest.php diff --git a/core/modules/node/src/Plugin/views/argument/UidRevision.php b/core/modules/node/src/Plugin/views/argument/UidRevision.php index 9e2fb810c2c..0f989a7a332 100644 --- a/core/modules/node/src/Plugin/views/argument/UidRevision.php +++ b/core/modules/node/src/Plugin/views/argument/UidRevision.php @@ -15,7 +15,7 @@ class UidRevision extends Uid { public function query($group_by = FALSE) { $this->ensureMyTable(); $placeholder = $this->placeholder(); - $this->query->addWhereExpression(0, "$this->tableAlias.revision_uid = $placeholder OR ((SELECT COUNT(DISTINCT vid) FROM {node_revision} nr WHERE nfr.revision_uid = $placeholder AND nr.nid = $this->tableAlias.nid) > 0)", [$placeholder => $this->argument]); + $this->query->addWhereExpression(0, "$this->tableAlias.uid = $placeholder OR ((SELECT COUNT(DISTINCT vid) FROM {node_revision} nr WHERE nr.revision_uid = $placeholder AND nr.nid = $this->tableAlias.nid) > 0)", [$placeholder => $this->argument]); } } diff --git a/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_argument_node_uid_revision.yml b/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_argument_node_uid_revision.yml new file mode 100644 index 00000000000..00ee678fc5a --- /dev/null +++ b/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_argument_node_uid_revision.yml @@ -0,0 +1,106 @@ +langcode: en +status: true +dependencies: + module: + - node + - user +id: test_argument_node_uid_revision +label: test_argument_node_uid_revision +module: views +description: '' +tag: default +base_table: node_field_data +base_field: nid +core: 8.0-dev +display: + default: + display_options: + access: + type: perm + cache: + type: tag + exposed_form: + type: basic + fields: + nid: + id: nid + table: node_field_data + field: nid + plugin_id: field + entity_type: node + entity_field: nid + filter_groups: + groups: + 1: AND + operator: AND + filters: { } + sorts: + nid: + id: nid + table: node_field_data + field: nid + order: ASC + plugin_id: standard + relationship: none + entity_type: node + entity_field: nid + pager: + type: full + query: + type: views_query + style: + type: default + row: + type: fields + display_extenders: { } + arguments: + uid_revision: + id: uid_revision + table: node_field_data + field: uid_revision + relationship: none + group_type: group + admin_label: '' + default_action: empty + exception: + value: all + title_enable: false + title: All + title_enable: false + title: '' + default_argument_type: fixed + default_argument_options: + argument: '' + default_argument_skip_url: false + summary_options: + base_path: '' + count: true + items_per_page: 25 + override: false + summary: + sort_order: asc + number_of_records: 0 + format: default_summary + specify_validation: false + validate: + type: none + fail: 'not found' + validate_options: { } + break_phrase: false + not: false + entity_type: node + plugin_id: node_uid_revision + display_plugin: default + display_title: Master + id: default + position: 0 + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - url + - url.query_args + - 'user.node_grants:view' + - user.permissions + tags: { } diff --git a/core/modules/node/tests/src/Kernel/Views/ArgumentUidRevisionTest.php b/core/modules/node/tests/src/Kernel/Views/ArgumentUidRevisionTest.php new file mode 100644 index 00000000000..b216f40fb26 --- /dev/null +++ b/core/modules/node/tests/src/Kernel/Views/ArgumentUidRevisionTest.php @@ -0,0 +1,93 @@ +installEntitySchema('node'); + $this->installSchema('node', ['node_access']); + $this->installEntitySchema('user'); + $this->installConfig(['node', 'field']); + + ViewTestData::createTestViews(get_class($this), ['node_test_views']); + } + + /** + * Tests the node_uid_revision argument. + */ + public function testArgument() { + $expected_result = []; + + $author = $this->createUser(); + $no_author = $this->createUser(); + + // Create one node, with the author as the node author. + $node1 = Node::create([ + 'type' => 'default', + 'title' => $this->randomMachineName(), + ]); + $node1->setOwner($author); + $node1->save(); + $expected_result[] = ['nid' => $node1->id()]; + + // Create one node of which an additional revision author will be the + // author. + $node2 = Node::create([ + 'type' => 'default', + 'title' => $this->randomMachineName(), + ]); + $node2->setRevisionAuthorId($no_author->id()); + $node2->save(); + $expected_result[] = ['nid' => $node2->id()]; + + // Force to add a new revision. + $node2->setNewRevision(TRUE); + $node2->setRevisionAuthorId($author->id()); + $node2->save(); + + // Create one node on which the author has neither authorship of revisions + // or the main node. + $node3 = Node::create([ + 'type' => 'default', + 'title' => $this->randomMachineName(), + ]); + $node3->setOwner($no_author); + $node3->save(); + + $view = Views::getView('test_argument_node_uid_revision'); + $view->initHandlers(); + $view->setArguments(['uid_revision' => $author->id()]); + + $this->executeView($view); + $this->assertIdenticalResultset($view, $expected_result, ['nid' => 'nid']); + } + +}