diff --git a/includes/ajax.inc b/includes/ajax.inc index f4e110f8a0fbf29e63e3244ef9ed9a37aa6572b6..ab562429c6eb62b39f87f471a3d07ba22d17dafb 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 0000000000000000000000000000000000000000..f358a6c643d1d2b5ab8bf29f921fa1d944a4cff9 --- /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 0000000000000000000000000000000000000000..17bbc798548fa138f210048b7340d34d476f1fc6 --- /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 fb2f5641a3bfb06b7fb7fc0247476765cb0d6e85..77a121b7ccb328d6c06b61424744d0437b28346b 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 0000000000000000000000000000000000000000..39007b817a3d35c1fb123da771791614aa7cbf6b --- /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