Issue #3132145 by mohit_aghera, codersukanta, osab, mashot7, Lendude: Views contextual filter: "allow multiple" doesn't work for user roles filter
parent
c7774d2181
commit
eb2ed2340f
|
@ -233,7 +233,7 @@ class UserViewsData extends EntityViewsData {
|
|||
'name field' => 'name',
|
||||
'empty field name' => $this->t('No role'),
|
||||
'zero is null' => TRUE,
|
||||
'numeric' => TRUE,
|
||||
'numeric' => FALSE,
|
||||
];
|
||||
|
||||
$data['user__roles']['permission'] = [
|
||||
|
|
|
@ -0,0 +1,192 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- user
|
||||
id: test_user_role_contextual_filter
|
||||
label: 'Test User Role Contextual Filter'
|
||||
module: views
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: users_field_data
|
||||
base_field: uid
|
||||
display:
|
||||
default:
|
||||
display_plugin: default
|
||||
id: default
|
||||
display_title: Default
|
||||
position: 0
|
||||
display_options:
|
||||
access:
|
||||
type: perm
|
||||
options:
|
||||
perm: 'access user profiles'
|
||||
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: mini
|
||||
options:
|
||||
items_per_page: 10
|
||||
offset: 0
|
||||
id: 0
|
||||
total_pages: null
|
||||
expose:
|
||||
items_per_page: false
|
||||
items_per_page_label: 'Items per page'
|
||||
items_per_page_options: '5, 10, 25, 50'
|
||||
items_per_page_options_all: false
|
||||
items_per_page_options_all_label: '- All -'
|
||||
offset: false
|
||||
offset_label: Offset
|
||||
tags:
|
||||
previous: ‹‹
|
||||
next: ››
|
||||
style:
|
||||
type: default
|
||||
options:
|
||||
grouping: { }
|
||||
row_class: ''
|
||||
default_row_class: true
|
||||
uses_fields: false
|
||||
row:
|
||||
type: fields
|
||||
options:
|
||||
inline: { }
|
||||
separator: ''
|
||||
hide_empty: false
|
||||
default_field_elements: true
|
||||
fields:
|
||||
name:
|
||||
id: name
|
||||
table: users_field_data
|
||||
field: name
|
||||
entity_type: user
|
||||
entity_field: name
|
||||
label: ''
|
||||
alter:
|
||||
alter_text: false
|
||||
make_link: false
|
||||
absolute: false
|
||||
trim: false
|
||||
word_boundary: false
|
||||
ellipsis: false
|
||||
strip_tags: false
|
||||
html: false
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
plugin_id: field
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
exclude: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: true
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_alter_empty: true
|
||||
click_sort_column: value
|
||||
type: user_name
|
||||
settings: { }
|
||||
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
|
||||
filters:
|
||||
status:
|
||||
value: '1'
|
||||
table: users_field_data
|
||||
field: status
|
||||
plugin_id: boolean
|
||||
entity_type: user
|
||||
entity_field: status
|
||||
id: status
|
||||
expose:
|
||||
operator: ''
|
||||
operator_limit_selection: false
|
||||
operator_list: { }
|
||||
group: 1
|
||||
sorts: { }
|
||||
header: { }
|
||||
footer: { }
|
||||
empty: { }
|
||||
relationships: { }
|
||||
arguments:
|
||||
roles_target_id:
|
||||
id: roles_target_id
|
||||
table: user__roles
|
||||
field: roles_target_id
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
default_action: ignore
|
||||
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: true
|
||||
add_table: false
|
||||
require_value: false
|
||||
reduce_duplicates: false
|
||||
entity_type: user
|
||||
entity_field: roles
|
||||
plugin_id: user__roles_rid
|
||||
display_extenders: { }
|
||||
cache_metadata:
|
||||
max-age: -1
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url
|
||||
- url.query_args
|
||||
- user.permissions
|
||||
tags: { }
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
|
||||
/**
|
||||
* Test contextual filters with 'allow multiple values' setting for user roles.
|
||||
*
|
||||
* @group views
|
||||
*/
|
||||
class ContextualFiltersStringTest extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $modules = [
|
||||
'views_ui',
|
||||
'views_test_config',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $defaultTheme = 'classy';
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_user_role_contextual_filter'];
|
||||
|
||||
/**
|
||||
* Role id of role 1.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $role1;
|
||||
|
||||
/**
|
||||
* Role id of role 2.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $role2;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp($import_test_views = TRUE): void {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
// Create Roles and users.
|
||||
$this->role1 = $this->drupalCreateRole(['access content'], 'editor', 'Editor');
|
||||
$this->role2 = $this->drupalCreateRole(['access content'], 'publisher', 'Publisher');
|
||||
|
||||
$this->createUser([], 'user1', FALSE, ['roles' => [$this->role1]]);
|
||||
$this->createUser([], 'user2', FALSE, ['roles' => [$this->role2]]);
|
||||
$this->createUser([], 'user3', FALSE, ['roles' => [$this->role1, $this->role2]]);
|
||||
$this->createUser([], 'user4', FALSE, ['roles' => [$this->role2]]);
|
||||
$this->createUser([], 'user5', FALSE, ['roles' => [$this->role1, $this->role2]]);
|
||||
|
||||
$this->drupalLogin($this->rootUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests contextual filter for the user roles.
|
||||
*/
|
||||
public function testUserRoleContextualFilter() {
|
||||
$this->drupalGet('admin/structure/views/view/test_user_role_contextual_filter');
|
||||
$edit = [
|
||||
'view_args' => $this->role1,
|
||||
];
|
||||
$this->submitForm($edit, 'Update preview');
|
||||
$this->assertSession()->pageTextContains('user1');
|
||||
$this->assertSession()->pageTextContains('user3');
|
||||
$this->assertSession()->pageTextContains('user5');
|
||||
$this->assertSession()->pageTextNotContains('user2');
|
||||
$this->assertSession()->pageTextNotContains('user4');
|
||||
|
||||
$edit = [
|
||||
'view_args' => $this->role2,
|
||||
];
|
||||
$this->submitForm($edit, 'Update preview');
|
||||
$this->assertSession()->pageTextContains('user2');
|
||||
$this->assertSession()->pageTextContains('user3');
|
||||
$this->assertSession()->pageTextContains('user4');
|
||||
$this->assertSession()->pageTextContains('user5');
|
||||
$this->assertSession()->pageTextNotContains('user1');
|
||||
|
||||
$edit = [
|
||||
'view_args' => "$this->role1,$this->role2",
|
||||
];
|
||||
$this->submitForm($edit, 'Update preview');
|
||||
$this->assertSession()->pageTextContains('user3');
|
||||
$this->assertSession()->pageTextContains('user5');
|
||||
$this->assertSession()->pageTextNotContains('user1');
|
||||
$this->assertSession()->pageTextNotContains('user2');
|
||||
$this->assertSession()->pageTextNotContains('user4');
|
||||
|
||||
$edit = [
|
||||
'view_args' => "$this->role1+$this->role2",
|
||||
];
|
||||
$this->submitForm($edit, 'Update preview');
|
||||
$this->assertSession()->pageTextContains('user1');
|
||||
$this->assertSession()->pageTextContains('user2');
|
||||
$this->assertSession()->pageTextContains('user3');
|
||||
$this->assertSession()->pageTextContains('user4');
|
||||
$this->assertSession()->pageTextContains('user5');
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue