public function QueryGroupByTest::groupByTestHelper in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/views/src/Tests/QueryGroupByTest.php \Drupal\views\Tests\QueryGroupByTest::groupByTestHelper()
Provides a test helper which runs a view with some aggregation function.
Parameters
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.
array $values: The expected views result.
6 calls to QueryGroupByTest::groupByTestHelper()
- QueryGroupByTest::testGroupByAverage in core/
modules/ views/ src/ Tests/ QueryGroupByTest.php - Tests the average aggregation function.
- QueryGroupByTest::testGroupByCount in core/
modules/ views/ src/ Tests/ QueryGroupByTest.php - Tests the count aggregation function.
- QueryGroupByTest::testGroupByMax in core/
modules/ views/ src/ Tests/ QueryGroupByTest.php - Tests the max aggregation function.
- QueryGroupByTest::testGroupByMin in core/
modules/ views/ src/ Tests/ QueryGroupByTest.php - Tests the min aggregation function.
- QueryGroupByTest::testGroupByNone in core/
modules/ views/ src/ Tests/ QueryGroupByTest.php - Tests aggregation with no specific function.
File
- core/
modules/ views/ src/ Tests/ QueryGroupByTest.php, line 90 - Contains \Drupal\views\Tests\QueryGroupByTest.
Class
- QueryGroupByTest
- Tests aggregate functionality of views, for example count.
Namespace
Drupal\views\TestsCode
public function groupByTestHelper($aggregation_function, $values) {
$this
->setupTestEntities();
$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.');
// Group by name to identify the right count.
$results = array();
foreach ($view->result as $item) {
$results[$item->entity_test_name] = $item->id;
}
$this
->assertEqual($results['name1'], $values[0], format_string('Aggregation with @aggregation_function and groupby name: name1 returned the expected amount of results', array(
'@aggregation_function' => $aggregation_function,
)));
$this
->assertEqual($results['name2'], $values[1], format_string('Aggregation with @aggregation_function and groupby name: name2 returned the expected amount of results', array(
'@aggregation_function' => $aggregation_function,
)));
}