Commit 7f11ec78 authored by alexpott's avatar alexpott

Issue #2564495 by geertvd, olli: Node ID contextual filter uses wrong handler

parent e686c9d1
......@@ -24,7 +24,7 @@ public function getViewsData() {
$data['node_field_data']['table']['base']['access query tag'] = 'node_access';
$data['node_field_data']['table']['wizard_id'] = 'node';
$data['node_field_data']['nid']['field']['argument'] = [
$data['node_field_data']['nid']['argument'] = [
'id' => 'node_nid',
'name field' => 'title',
'numeric' => TRUE,
......
<?php
/**
* @file
* Contains \Drupal\node\Tests\Views\NidArgumentTest.
*/
namespace Drupal\node\Tests\Views;
use Drupal\node\Entity\Node;
use Drupal\views\Tests\ViewKernelTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
/**
* Tests the nid argument handler.
*
* @group node
* @see \Drupal\node\Plugin\views\argument\Nid
*/
class NidArgumentTest extends ViewKernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['node', 'field', 'text', 'node_test_config', 'user', 'entity_reference', 'node_test_views'];
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_nid_argument'];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->installEntitySchema('node');
$this->installEntitySchema('user');
$this->installConfig(['node', 'field']);
ViewTestData::createTestViews(get_class($this), ['node_test_views']);
}
/**
* Test the nid argument.
*/
public function testNidArgument() {
$view = Views::getView('test_nid_argument');
$view->setDisplay();
$node1 = Node::create([
'type' => 'default',
'title' => $this->randomMachineName(),
]);
$node1->save();
$node2 = Node::create([
'type' => 'default',
'title' => $this->randomMachineName(),
]);
$node2->save();
$view->preview();
$this->assertEqual(count($view->result), 2, 'Found the expected number of results.');
// Set an the second node id as an argument.
$view->destroy();
$view->preview('default', [$node2->id()]);
// Verify that the title is overridden.
$this->assertEqual($view->getTitle(), $node2->getTitle());
// Verify that the argument filtering works.
$this->assertEqual(count($view->result), 1, 'Found the expected number of results.');
$this->assertEqual($node2->id(), (string) $view->style_plugin->getField(0, 'nid'), 'Found the correct nid.');
// Verify that setting a non-existing id as argument results in no nodes
// being shown.
$view->destroy();
$view->preview('default', [22]);
$this->assertEqual(count($view->result), 0, 'Found the expected number of results.');
}
}
langcode: en
status: true
dependencies:
module:
- node
- user
id: test_nid_argument
label: test_nid_argument
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: perm
options:
perm: 'access content'
cache:
type: tag
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: 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: null
offset: 0
style:
type: default
row:
type: fields
fields:
nid:
id: nid
table: node
field: nid
relationship: none
group_type: group
admin_label: ''
label: ''
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: 0
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: false
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: value
type: number_integer
settings:
thousand_separator: ''
prefix_suffix: true
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
entity_type: node
entity_field: nid
plugin_id: field
filters: { }
sorts: { }
title: test_nid_argument
header: { }
footer: { }
empty: { }
relationships: { }
arguments:
nid:
id: nid
table: node_field_data
field: nid
relationship: none
group_type: group
admin_label: ''
default_action: ignore
exception:
value: all
title_enable: false
title: All
title_enable: true
title: '{{ arguments.nid }}'
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
entity_field: nid
plugin_id: node_nid
display_extenders: { }
cache_metadata:
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- 'user.node_grants:view'
- user.permissions
cacheable: false
page_1:
display_plugin: page
id: page_1
display_title: Page
position: 1
display_options:
display_extenders: { }
path: test-nid-argument
cache_metadata:
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- 'user.node_grants:view'
- user.permissions
cacheable: false
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