From 6b8cc669d4b7b4a1df0f06fdaec167756da82bba Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Mon, 4 May 2015 17:13:00 -0700 Subject: [PATCH] Issue #2469563 by marthinal, lauriii, dawehner, Fabianx, xjm, pjonckiere: Double-escape on Views filters --- .../views/src/Tests/Handler/HandlerTest.php | 20 ----- .../views_ui/src/Tests/FilterUITest.php | 78 +++++++++++++++++++ core/modules/views_ui/src/ViewEditForm.php | 7 +- 3 files changed, 84 insertions(+), 21 deletions(-) create mode 100644 core/modules/views_ui/src/Tests/FilterUITest.php diff --git a/core/modules/views/src/Tests/Handler/HandlerTest.php b/core/modules/views/src/Tests/Handler/HandlerTest.php index 4904baf3dada..f084f90572a6 100644 --- a/core/modules/views/src/Tests/Handler/HandlerTest.php +++ b/core/modules/views/src/Tests/Handler/HandlerTest.php @@ -68,26 +68,6 @@ protected function viewsData() { return $data; } - /** - * @todo - * This should probably moved to a filter related test. - */ - function testFilterInOperatorUi() { - $admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration')); - $this->drupalLogin($admin_user); - - $path = 'admin/structure/views/nojs/handler/test_filter_in_operator_ui/default/filter/type'; - $this->drupalGet($path); - $this->assertFieldByName('options[expose][reduce]', FALSE); - - $edit = array( - 'options[expose][reduce]' => TRUE, - ); - $this->drupalPostForm($path, $edit, t('Apply')); - $this->drupalGet($path); - $this->assertFieldByName('options[expose][reduce]', TRUE); - } - /** * Tests the breakString method. */ diff --git a/core/modules/views_ui/src/Tests/FilterUITest.php b/core/modules/views_ui/src/Tests/FilterUITest.php new file mode 100644 index 000000000000..4d8f5fea25c3 --- /dev/null +++ b/core/modules/views_ui/src/Tests/FilterUITest.php @@ -0,0 +1,78 @@ +<?php + +/** + * @file + * Contains \Drupal\views\Tests\FilterUITest. + */ + +namespace Drupal\views_ui\Tests; + +use Drupal\views\Tests\ViewTestBase; + +/** + * Tests for the filters from the UI. + * + * @group views_ui + */ +class FilterUITest extends ViewTestBase { + + + /** + * Views used by this test. + * + * @var array + */ + public static $testViews = array('test_filter_in_operator_ui', 'test_filter_groups'); + + /** + * Modules to enable. + * + * @var array + */ + public static $modules = array('views_ui', 'node'); + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $this->drupalCreateContentType(array('type' => 'page')); + $this->enableViewsTestModule(); + } + + /** + * Tests that an option for a filter is saved as expected from the UI. + */ + public function testFilterInOperatorUi() { + $admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration')); + $this->drupalLogin($admin_user); + + $path = 'admin/structure/views/nojs/handler/test_filter_in_operator_ui/default/filter/type'; + $this->drupalGet($path); + // Verifies that "Limit list to selected items" option is not selected. + $this->assertFieldByName('options[expose][reduce]', FALSE); + + // Select "Limit list to selected items" option and apply. + $edit = array( + 'options[expose][reduce]' => TRUE, + ); + $this->drupalPostForm($path, $edit, t('Apply')); + + // Verifies that the option was saved as expected. + $this->drupalGet($path); + $this->assertFieldByName('options[expose][reduce]', TRUE); + } + + /** + * Tests the filters from the UI. + */ + public function testFiltersUI() { + $admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration')); + $this->drupalLogin($admin_user); + + $this->drupalGet('admin/structure/views/view/test_filter_groups'); + + $this->assertLink('Content: Node ID (= 1)', 0, 'Content: Node ID (= 1) link appears correctly.'); + } + +} diff --git a/core/modules/views_ui/src/ViewEditForm.php b/core/modules/views_ui/src/ViewEditForm.php index 6314b8553559..221528c92f7d 100644 --- a/core/modules/views_ui/src/ViewEditForm.php +++ b/core/modules/views_ui/src/ViewEditForm.php @@ -1143,7 +1143,12 @@ public function getFormBucket(ViewUI $view, $type, $display) { $last = end($keys); foreach ($contents as $key => $pid) { if ($key != $last) { - $store[$pid]['#link'] .= ' ' . ($group_info['groups'][$gid] == 'OR' ? $this->t('OR') : $this->t('AND')); + if ($group_info['groups'][$gid] == 'OR') { + $store[$pid]['#link'] = $this->t('!link OR', ['!link' => $store[$pid]['#link']]); + } + else { + $store[$pid]['#link'] = $this->t('!link AND', ['!link' => $store[$pid]['#link']]); + } } $build['fields'][$pid] = $store[$pid]; } -- GitLab