Commit 23b70dfb authored by alexpott's avatar alexpott

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

parent 6ee87bc5
......@@ -1232,6 +1232,10 @@ public function query($get_count = FALSE) {
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));
......
......@@ -74,8 +74,9 @@ public function testAggregateCount() {
/**
* 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 @@ public function groupByTestHelper($aggregation_function, $values) {
$view = Views::getView('test_group_by_count');
$view->setDisplay();
$view->displayHandlers->get('default')->options['fields']['id']['group_type'] = $aggregation_function;
// 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 @@ public function groupByTestHelper($aggregation_function, $values) {
* 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 @@ public function testGroupByMax() {
$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.
*/
......
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