From cf22d23b0f33e267ab44aa92940c44f48ece8c99 Mon Sep 17 00:00:00 2001 From: dereine <dereine@99340.no-reply.drupal.org> Date: Sat, 8 Sep 2012 10:36:34 +0200 Subject: [PATCH] Issue #1777512 by dawehner: Fixed UidRevision filter handler uses undefined variable. --- includes/ajax.inc | 2 + .../Tests/Node/FilterUidRevisionTest.php | 58 +++++++++++++++++++ lib/Drupal/views/Tests/Node/NodeTestBase.php | 16 +++++ .../node/Plugin/views/filter/UidRevision.php | 2 +- ...ews.view.test_filter_node_uid_revision.yml | 54 +++++++++++++++++ 5 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 lib/Drupal/views/Tests/Node/FilterUidRevisionTest.php create mode 100644 lib/Drupal/views/Tests/Node/NodeTestBase.php create mode 100644 tests/views_test_config/config/views.view.test_filter_node_uid_revision.yml diff --git a/includes/ajax.inc b/includes/ajax.inc index f4e110f8a0fb..ab562429c6eb 100644 --- a/includes/ajax.inc +++ b/includes/ajax.inc @@ -5,6 +5,8 @@ * Handles the server side AJAX interactions of Views. */ +use Symfony\Component\HttpFoundation\JsonResponse; + /** * @defgroup ajax Views AJAX library * @{ diff --git a/lib/Drupal/views/Tests/Node/FilterUidRevisionTest.php b/lib/Drupal/views/Tests/Node/FilterUidRevisionTest.php new file mode 100644 index 000000000000..f358a6c643d1 --- /dev/null +++ b/lib/Drupal/views/Tests/Node/FilterUidRevisionTest.php @@ -0,0 +1,58 @@ +<?php + +/** + * @file + * Definition of Drupal\views\Tests\Comment\FilterUidRevisionTest. + */ + +namespace Drupal\views\Tests\Node; + +/** + * Tests the node_uid_revision handler. + */ +class FilterUidRevisionTest extends NodeTestBase { + + public static function getInfo() { + return array( + 'name' => 'Node: User has revision Filter', + 'description' => 'Tests the node_uid_revision handler.', + 'group' => 'Views Modules', + ); + } + + + /** + * Tests the node_uid_revision filter. + */ + public function testFilter() { + $author = $this->drupalCreateUser(); + $no_author = $this->drupalCreateUser(); + + $expected_result = array(); + // Create one node, with the author as the node author. + $node = $this->drupalCreateNode(array('uid' => $author->id())); + $expected_result[] = array('nid' => $node->id()); + // Create one node of which an additional revision author will be the + // author. + $node = $this->drupalCreateNode(array('uid' => $no_author->id())); + $expected_result[] = array('nid' => $node->id()); + $revision = clone $node; + // Force to add a new revision. + $revision->set('vid', NULL); + $revision->set('revision_uid', $author->id()); + $revision->save(); + + // Create one node on which the author has neither authorship of revisions + // or the main node. + $node = $this->drupalCreateNode(array('uid' => $no_author->id())); + + $view = views_get_view('test_filter_node_uid_revision'); + $view->initDisplay(); + $view->initHandlers(); + $view->filter['uid_revision']->value = array($author->uid); + + $this->executeView($view); + $this->assertIdenticalResultset($view, $expected_result, array('nid' => 'nid'), 'Make sure that the view only returns nodes which match either the node or the revision author.'); + } + +} diff --git a/lib/Drupal/views/Tests/Node/NodeTestBase.php b/lib/Drupal/views/Tests/Node/NodeTestBase.php new file mode 100644 index 000000000000..17bbc798548f --- /dev/null +++ b/lib/Drupal/views/Tests/Node/NodeTestBase.php @@ -0,0 +1,16 @@ +<?php + +/** + * @file + * Definition of Drupal\views\Tests\Node\NodeTestBase. + */ + +namespace Drupal\views\Tests\Node; + +use Drupal\views\Tests\ViewTestBase; + +/** + * Base class for all node tests. + */ +abstract class NodeTestBase extends ViewTestBase { +} diff --git a/lib/Views/node/Plugin/views/filter/UidRevision.php b/lib/Views/node/Plugin/views/filter/UidRevision.php index fb2f5641a3bf..77a121b7ccb3 100644 --- a/lib/Views/node/Plugin/views/filter/UidRevision.php +++ b/lib/Views/node/Plugin/views/filter/UidRevision.php @@ -29,7 +29,7 @@ public function query($group_by = FALSE) { $args = array_values($this->value); - $this->query->add_where_expression($this->options['group'], "$this->table_alias.uid IN($placeholder) " . $condition . " OR + $this->query->add_where_expression($this->options['group'], "$this->table_alias.uid IN($placeholder) OR ((SELECT COUNT(*) FROM {node_revision} nr WHERE nr.uid IN($placeholder) AND nr.nid = $this->table_alias.nid) > 0)", array($placeholder => $args), $args); } diff --git a/tests/views_test_config/config/views.view.test_filter_node_uid_revision.yml b/tests/views_test_config/config/views.view.test_filter_node_uid_revision.yml new file mode 100644 index 000000000000..39007b817a3d --- /dev/null +++ b/tests/views_test_config/config/views.view.test_filter_node_uid_revision.yml @@ -0,0 +1,54 @@ +api_version: '3.0' +base_table: node +core: 8.0-dev +description: '' +disabled: '0' +display: + default: + display_options: + access: + type: perm + cache: + type: none + exposed_form: + type: basic + fields: + nid: + id: nid + table: node + field: nid + filter_groups: + groups: + 1: AND + operator: AND + filters: + uid_revision: + admin_label: '' + field: uid_revision + id: uid_revision + is_grouped: '0' + operator: in + relationship: none + table: node + value: + - '1' + sorts: + nid: + id: nid + table: node + field: nid + order: asc + pager: + type: full + query: + type: views_query + row_plugin: fields + sorts: { } + style_plugin: default + display_plugin: default + display_title: Master + id: default + position: '0' +human_name: test_filter_node_uid_revision +name: test_filter_node_uid_revision +tag: default -- GitLab