Commit fb8335a9 authored by alexpott's avatar alexpott

Issue #2858159 by Artusamak, Lendude: The "User has a revision" views argument...

Issue #2858159 by Artusamak, Lendude: The "User has a revision" views argument handler generates a SQL error
parent 55e309fc
......@@ -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]);
}
}
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: { }
<?php
namespace Drupal\Tests\node\Kernel\Views;
use Drupal\node\Entity\Node;
use Drupal\simpletest\UserCreationTrait;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
/**
* Tests the argument_node_uid_revision handler.
*
* @group node
*/
class ArgumentUidRevisionTest extends ViewsKernelTestBase {
use UserCreationTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['node', 'field', 'text', 'user', 'node_test_views'];
/**
* {@inheritdoc}
*/
public static $testViews = ['test_argument_node_uid_revision'];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->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']);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment