Issue #2159347 by david_garcia, claudiu.cristea: Aggregation not working simple test case

8.0.x
Alex Pott 2014-11-28 12:49:12 +00:00
parent 6ee87bc5ab
commit 23b70dfb16
2 changed files with 25 additions and 4 deletions

View File

@ -1232,6 +1232,10 @@ class Sql extends QueryPluginBase {
if (count($this->having)) {
$this->hasAggregate = TRUE;
}
elseif ($this->hasAggregate == FALSE) {
// Allow 'GROUP BY' even no aggregation function has been set.
$this->hasAggregate = $this->view->display_handler->getOption('group_by');
}
$groupby = array();
if ($this->hasAggregate && (!empty($this->groupby) || !empty($non_aggregates))) {
$groupby = array_unique(array_merge($this->groupby, $non_aggregates));

View File

@ -74,8 +74,9 @@ class QueryGroupByTest extends ViewUnitTestBase {
/**
* Provides a test helper which runs a view with some aggregation function.
*
* @param string $aggregation_function
* Which aggregation function should be used, for example sum or count.
* @param string|null $aggregation_function
* Which aggregation function should be used, for example sum or count. If
* NULL is passed the aggregation will be tested with no function.
* @param array $values
* The expected views result.
*/
@ -84,7 +85,16 @@ class QueryGroupByTest extends ViewUnitTestBase {
$view = Views::getView('test_group_by_count');
$view->setDisplay();
// There is no need for a function in order to have aggregation.
if (empty($aggregation_function)) {
// The test table has 2 fields ('id' and 'name'). We'll remove 'id'
// because it's unique and will test aggregation on 'name'.
unset($view->displayHandlers->get('default')->options['fields']['id']);
}
else {
$view->displayHandlers->get('default')->options['fields']['id']['group_type'] = $aggregation_function;
}
$this->executeView($view);
$this->assertEqual(count($view->result), 2, 'Make sure the count of items is right.');
@ -101,7 +111,7 @@ class QueryGroupByTest extends ViewUnitTestBase {
* Helper method that creates some test entities.
*/
protected function setupTestEntities() {
// Create 4 entities with name1 and 3 nodes with name2.
// Create 4 entities with name1 and 3 entities with name2.
$entity_1 = array(
'name' => 'name1',
);
@ -154,6 +164,13 @@ class QueryGroupByTest extends ViewUnitTestBase {
$this->groupByTestHelper('max', array(4, 7));
}
/**
* Tests aggregation with no specific function.
*/
public function testGroupByNone() {
$this->groupByTestHelper(NULL, array(1, 5));
}
/**
* Tests groupby with filters.
*/