Commit 704c66e8 authored by alexpott's avatar alexpott

Issue #2634156 by dpi, jian he, dawehner: Missing configuration schema and...

Issue #2634156 by dpi, jian he, dawehner: Missing configuration schema and tests for "user_current" views filter handler

(cherry picked from commit 3a90d689)
parent b455c23d
......@@ -98,3 +98,7 @@ views.filter.user_permissions:
views.filter.user_roles:
type: views.filter.many_to_one
label: 'Role'
views.filter_value.user_current:
type: views.filter_value.boolean
label: 'Current user'
langcode: en
status: true
dependencies:
module:
- user
id: test_filter_current_user
label: Users
module: views
description: ''
tag: ''
base_table: users_field_data
base_field: uid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: none
cache:
type: tag
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
exposed_form:
type: basic
options:
submit_button: Filter
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:
offset: 0
style:
type: default
options:
row_class: ''
default_row_class: true
uses_fields: false
row:
type: fields
options:
separator: ''
hide_empty: false
default_field_elements: true
fields:
uid:
id: uid
table: users
field: uid
relationship: none
group_type: group
admin_label: ''
label: ''
exclude: false
filters:
uid_current:
id: uid_current
table: users
field: uid_current
relationship: none
group_type: group
admin_label: ''
operator: '='
value: '1'
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
entity_type: user
plugin_id: user_current
sorts: { }
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }
display_extenders: { }
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- user
tags: { }
<?php
namespace Drupal\Tests\user\Kernel\Views;
use Drupal\views\Views;
use Drupal\Core\Session\AnonymousUserSession;
/**
* Tests the current user filter handler.
*
* @group user
* @see \Drupal\user\Plugin\views\filter\Current
*/
class HandlerFilterCurrentUserTest extends UserKernelTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_filter_current_user'];
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxy
*/
protected $currentUser;
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp();
$this->currentUser = $this->container->get('current_user');
$this->setupPermissionTestData();
}
/**
* Tests the current user filter handler with anonymous user.
*/
public function testFilterCurrentUserAsAnonymous() {
$column_map = ['uid' => 'uid'];
$this->currentUser->setAccount(new AnonymousUserSession());
$view = Views::getView('test_filter_current_user');
$view->initHandlers();
$view->filter['uid_current']->value = 0;
$this->executeView($view);
$expected[] = ['uid' => 1];
$expected[] = ['uid' => 2];
$expected[] = ['uid' => 3];
$expected[] = ['uid' => 4];
$this->assertIdenticalResultset($view, $expected, $column_map, 'Anonymous account can view all accounts when current filter is FALSE.');
$view->destroy();
$view = Views::getView('test_filter_current_user');
$view->initHandlers();
$view->filter['uid_current']->value = 1;
$this->executeView($view);
$expected = [];
$this->assertIdenticalResultset($view, $expected, $column_map, 'Anonymous account can view zero accounts when current filter is TRUE.');
$view->destroy();
}
/**
* Tests the current user filter handler with logged-in user.
*/
public function testFilterCurrentUserAsUser() {
$column_map = ['uid' => 'uid'];
$user = reset($this->users);
$this->currentUser->setAccount($user);
$view = Views::getView('test_filter_current_user');
$view->initHandlers();
$view->filter['uid_current']->value = 0;
$this->executeView($view);
$expected = [];
$expected[] = ['uid' => 2];
$expected[] = ['uid' => 3];
$expected[] = ['uid' => 4];
$this->assertIdenticalResultset($view, $expected, $column_map, 'User can view all users except itself when current filter is FALSE.');
$view->destroy();
$view = Views::getView('test_filter_current_user');
$view->initHandlers();
$view->filter['uid_current']->value = 1;
$this->executeView($view);
$expected = [];
$expected[] = ['uid' => 1];
$this->assertIdenticalResultset($view, $expected, $column_map, 'User can only view itself when current filter is TRUE.');
$view->destroy();
}
}
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