Commit ed9b912d authored by alexpott's avatar alexpott

Issue #2561973 by geertvd, DuaelFr, Lendude: Unable to save view with permission filter handler

parent 6b464107
<?php
/**
* @file
* Contains \Drupal\user\Tests\Views\FilterPermissionUiTest.
*/
namespace Drupal\user\Tests\Views;
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
/**
* Tests the permission field handler ui.
*
* @group user
* @see \Drupal\user\Plugin\views\filter\Permissions
*/
class FilterPermissionUiTest extends ViewTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_filter_permission'];
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['user', 'user_test_views', 'views_ui'];
protected function setUp() {
parent::setUp(TRUE);
ViewTestData::createTestViews(get_class($this), array('user_test_views'));
$this->enableViewsTestModule();
}
/**
* Tests basic filter handler settings in the UI.
*/
public function testHandlerUI() {
$this->drupalLogin($this->drupalCreateUser(['administer views', 'administer users']));
$this->drupalGet('admin/structure/views/view/test_filter_permission/edit/default');
// Verify that the handler summary is correctly displaying the selected
// permission.
$this->assertLink('User: Permission (= View user information)');
$this->drupalPostForm(NULL, [], 'Save');
// Verify that we can save the view.
$this->assertNoText('No valid values found on filter: User: Permission.');
$this->assertText('The view test_filter_permission has been saved.');
// Verify that the handler summary is also correct when multiple values are
// selected in the filter.
$edit = [
'options[value][]' => [
'access user profiles',
'administer views',
],
];
$this->drupalPostForm('admin/structure/views/nojs/handler/test_filter_permission/default/filter/permission', $edit, 'Apply');
$this->assertLink('User: Permission (or View us…)');
$this->drupalPostForm(NULL, [], 'Save');
// Verify that we can save the view.
$this->assertNoText('No valid values found on filter: User: Permission.');
$this->assertText('The view test_filter_permission has been saved.');
}
}
......@@ -330,6 +330,8 @@ public function adminSummary() {
$info = $this->operators();
$this->getValueOptions();
// Some filter_in_operator usage uses optgroups forms, so flatten it.
$flat_options = OptGroup::flattenOptions($this->valueOptions);
if (!is_array($this->value)) {
return;
......@@ -340,7 +342,7 @@ public function adminSummary() {
if (in_array($this->operator, $this->operatorValues(1))) {
// Remove every element which is not known.
foreach ($this->value as $value) {
if (!isset($this->valueOptions[$value])) {
if (!isset($flat_options[$value])) {
unset($this->value[$value]);
}
}
......@@ -356,8 +358,8 @@ public function adminSummary() {
$keys = $this->value;
$value = array_shift($keys);
if (isset($this->valueOptions[$value])) {
$values = SafeMarkup::checkPlain($this->valueOptions[$value]);
if (isset($flat_options[$value])) {
$values = SafeMarkup::checkPlain($flat_options[$value]);
}
else {
$values = '';
......@@ -372,8 +374,8 @@ public function adminSummary() {
$values = Unicode::truncate($values, 8, FALSE, TRUE);
break;
}
if (isset($this->valueOptions[$value])) {
$values .= SafeMarkup::checkPlain($this->valueOptions[$value]);
if (isset($flat_options[$value])) {
$values .= SafeMarkup::checkPlain($flat_options[$value]);
}
}
}
......
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