diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/filter/Compare.php b/core/modules/views/lib/Drupal/views/Plugin/views/filter/Compare.php index 41df46d..1ab32be 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/filter/Compare.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/filter/Compare.php @@ -97,7 +97,7 @@ public function buildOptionsForm(&$form, &$form_state) { * {@inheritdoc} */ public function adminSummary() { - return check_plain( + return String::format( $this->options['left_field'] . ' ' . $this->options['operator'] . ' ' . $this->options['right_field'] @@ -107,7 +107,7 @@ public function adminSummary() { /** * {@inheritdoc} * - * Build extra condition from existing fields (from existing joins). + * Builds extra condition from existing fields (from existing joins). */ public function query() { $left = $this->options['left_field']; diff --git a/core/modules/views/lib/Drupal/views/Tests/Handler/FilterCompareTest.php b/core/modules/views/lib/Drupal/views/Tests/Handler/FilterCompareTest.php index bf98e92..b4298a2 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Handler/FilterCompareTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Handler/FilterCompareTest.php @@ -68,50 +68,54 @@ public function testCompare() { $this->assertIdenticalResultset($view, array(array('name' => 'John')), $this->columnMap); $view->destroy(); - // Test the inequality operator. - $view->initDisplay(); - $item = $view->getItem('default', 'filter', 'fields_compare'); - $item['operator'] = '!='; - $view->setItem('default', 'filter', 'fields_compare', $item); + $tests = array(); + $tests[] = array('=', array( + array('name' => 'John'), + )); + + $tests[] = array('!=', array( + array('name' => 'George'), + array('name' => 'Ringo'), + array('name' => 'Paul'), + array('name' => 'Meredith') + )); + + $tests[] = array('>', array( + array('name' => 'George'), + array('name' => 'Ringo'), + )); + + $tests[] = array('>=', array( + array('name' => 'John'), + array('name' => 'George'), + array('name' => 'Ringo'), + )); + + $tests[] = array('<', array( + array('name' => 'Paul'), + array('name' => 'Meredith'), + )); + + $tests[] = array('<=', array( + array('name' => 'John'), + array('name' => 'Paul'), + array('name' => 'Meredith'), + )); + + foreach ($tests as $parts) { + list($operator, $expected) = $parts; + + $view->initDisplay(); + $item = $view->getItem('default', 'filter', 'fields_compare'); + $item['operator'] = $operator; + $view->setItem('default', 'filter', 'fields_compare', $item); + + $this->executeView($view); + $this->assertIdenticalResultset($view, $expected, $this->columnMap); + $view->destroy(); + } - $this->executeView($view); - $expected = array(); - $expected[] = array('name' => 'George'); - $expected[] = array('name' => 'Ringo'); - $expected[] = array('name' => 'Paul'); - $expected[] = array('name' => 'Meredith'); - - $this->assertIdenticalResultset($view, $expected, $this->columnMap); - $view->destroy(); - - // Test the is greater than operator. - $view->initDisplay(); - $item = $view->getItem('default', 'filter', 'fields_compare'); - $item['operator'] = '>'; - $view->setItem('default', 'filter', 'fields_compare', $item); - - $this->executeView($view); - $expected = array(); - $expected[] = array('name' => 'George'); - $expected[] = array('name' => 'Ringo'); - $this->assertIdenticalResultset($view, $expected, $this->columnMap); - $view->destroy(); - - // Test the is greater than or equal operator. - $view->initDisplay(); - $item = $view->getItem('default', 'filter', 'fields_compare'); - $item['operator'] = '>='; - $view->setItem('default', 'filter', 'fields_compare', $item); - - $this->executeView($view); - $expected = array(); - $expected[] = array('name' => 'John'); - $expected[] = array('name' => 'George'); - $expected[] = array('name' => 'Ringo'); - - $this->assertIdenticalResultset($view, $expected, $this->columnMap); - $view->destroy(); } } diff --git a/core/modules/views/views.views.inc b/core/modules/views/views.views.inc index a2d09d8..beeff4c 100644 --- a/core/modules/views/views.views.inc +++ b/core/modules/views/views.views.inc @@ -124,9 +124,8 @@ function views_views_data() { $data['views']['fields_compare'] = array( 'title' => t('Fields comparison'), - 'help' => t('Compare database fields against each other.'), + 'help' => t('Compare two fields to filter the result of a view'), 'filter' => array( - 'help' => t('Use fields comparison to filter the result of the view.'), 'id' => 'compare', ) );