Commit c5b9bb0b authored by alexpott's avatar alexpott

Issue #2006560 by dawehner, jhodgdon: Fixed The boolean string filter doesn't...

Issue #2006560 by dawehner, jhodgdon: Fixed The boolean string filter doesn't result in correct where clause.
parent 0e100f3c
......@@ -37,7 +37,7 @@ public function query() {
else {
$where .= "<> ''";
}
$this->query->addWhere($this->options['group'], $where);
$this->query->addWhereExpression($this->options['group'], $where);
}
}
<?php
/**
* @file
* Contains \Drupal\views\Tests\Handler\FilterBooleanOperatorStringTest.
*/
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewUnitTestBase;
use Drupal\views\Views;
/**
* Tests the BooleanOperator filter handler.
*
* @see \Drupal\views\Plugin\views\filter\BooleanOperatorString
*/
class FilterBooleanOperatorStringTest extends ViewUnitTestBase {
/**
* The modules to enable for this test.
*
* @var array
*/
public static $modules = array('system');
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_view');
protected $column_map = array(
'views_test_data_id' => 'id',
);
public static function getInfo() {
return array(
'name' => 'Filter: Boolean string operator',
'description' => 'Test the core Drupal\views\Plugin\views\filter\BooleanOperatorString handler.',
'group' => 'Views Handlers',
);
}
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installSchema('system', array('menu_router', 'variable', 'key_value_expire'));
}
/**
* {@inheritdoc}
*/
protected function schemaDefinition() {
$schema = parent::schemaDefinition();
$schema['views_test_data']['fields']['status'] = array(
'description' => 'The status of this record',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
);
return $schema;
}
/**
* {@inheritdoc}
*/
protected function viewsData() {
$views_data = parent::viewsData();
$views_data['views_test_data']['status']['filter']['id'] = 'boolean_string';
return $views_data;
}
/**
* {@inheritdoc}
*/
protected function dataSet() {
$data = parent::dataSet();
foreach ($data as &$row) {
if ($row['status']) {
$row['status'] = 'Enabled';
}
else {
$row['status'] = '';
}
}
return $data;
}
/**
* Tests the BooleanOperatorString filter.
*/
public function testFilterBooleanOperatorString() {
$view = Views::getView('test_view');
$view->setDisplay();
// Add a the status boolean filter.
$view->displayHandlers->get('default')->overrideOption('filters', array(
'status' => array(
'id' => 'status',
'field' => 'status',
'table' => 'views_test_data',
'value' => 0,
),
));
$this->executeView($view);
$expected_result = array(
array('id' => 2),
array('id' => 4),
);
$this->assertEqual(2, count($view->result));
$this->assertIdenticalResultset($view, $expected_result, $this->column_map);
$view->destroy();
$view->setDisplay();
// Add the status boolean filter.
$view->displayHandlers->get('default')->overrideOption('filters', array(
'status' => array(
'id' => 'status',
'field' => 'status',
'table' => 'views_test_data',
'value' => 1,
),
));
$this->executeView($view);
$expected_result = array(
array('id' => 1),
array('id' => 3),
array('id' => 5),
);
$this->assertEqual(3, count($view->result));
$this->assertIdenticalResultset($view, $expected_result, $this->column_map);
}
/**
* Tests the Boolean filter with grouped exposed form enabled.
*/
public function testFilterGroupedExposed() {
$filters = $this->getGroupedExposedFilters();
$view = Views::getView('test_view');
$view->setExposedInput(array('status' => 1));
$view->setDisplay();
$view->displayHandlers->get('default')->overrideOption('filters', $filters);
$this->executeView($view);
$expected_result = array(
array('id' => 1),
array('id' => 3),
array('id' => 5),
);
$this->assertEqual(3, count($view->result));
$this->assertIdenticalResultset($view, $expected_result, $this->column_map);
$view->destroy();
$view->setExposedInput(array('status' => 2));
$view->setDisplay();
$view->displayHandlers->get('default')->overrideOption('filters', $filters);
$this->executeView($view);
$expected_result = array(
array('id' => 2),
array('id' => 4),
);
$this->assertEqual(2, count($view->result));
$this->assertIdenticalResultset($view, $expected_result, $this->column_map);
}
/**
* Provides grouped exposed filter configuration.
*
* @return array
* Returns the filter configuration for exposed filters.
*/
protected function getGroupedExposedFilters() {
$filters = array(
'status' => array(
'id' => 'status',
'table' => 'views_test_data',
'field' => 'status',
'relationship' => 'none',
'exposed' => TRUE,
'expose' => array(
'operator' => 'status_op',
'label' => 'status',
'identifier' => 'status',
),
'is_grouped' => TRUE,
'group_info' => array(
'label' => 'status',
'identifier' => 'status',
'default_group' => 'All',
'group_items' => array(
1 => array(
'title' => 'Active',
'operator' => '=',
'value' => '1',
),
2 => array(
'title' => 'Blocked',
'operator' => '=',
'value' => '0',
),
),
),
),
);
return $filters;
}
}
......@@ -7,6 +7,7 @@
namespace Drupal\views\Tests;
use Drupal\Core\Database\Query\SelectInterface;
use Drupal\simpletest\WebTestBase;
use Drupal\views\ViewExecutable;
use Drupal\block\Plugin\Core\Entity\Block;
......@@ -228,7 +229,11 @@ protected function executeView($view, $args = array()) {
$view->setDisplay();
$view->preExecute($args);
$view->execute();
$this->verbose('<pre>Executed view: ' . ((string) $view->build_info['query']) . '</pre>');
$verbose_message = '<pre>Executed view: ' . ((string) $view->build_info['query']). '</pre>';
if ($view->build_info['query'] instanceof SelectInterface) {
$verbose_message .= '<pre>Arguments: ' . print_r($view->build_info['query']->getArguments(), TRUE) . '</pre>';
}
$this->verbose($verbose_message);
}
/**
......
......@@ -7,6 +7,7 @@
namespace Drupal\views\Tests;
use Drupal\Core\Database\Query\SelectInterface;
use Drupal\views\ViewExecutable;
use Drupal\views\ViewsBundle;
use Drupal\simpletest\DrupalUnitTestBase;
......@@ -222,7 +223,11 @@ protected function executeView($view, $args = array()) {
$view->setDisplay();
$view->preExecute($args);
$view->execute();
$this->verbose('<pre>Executed view: ' . ((string) $view->build_info['query']) . '</pre>');
$verbose_message = '<pre>Executed view: ' . ((string) $view->build_info['query']). '</pre>';
if ($view->build_info['query'] instanceof SelectInterface) {
$verbose_message .= '<pre>Arguments: ' . print_r($view->build_info['query']->getArguments(), TRUE) . '</pre>';
}
$this->verbose($verbose_message);
}
/**
......
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