function QueryGroupByTest::GroupByTestHelper in Views (for Drupal 7) 8.3
Parameters
$group_by: Which group_by function should be used, for example sum or count.
5 calls to QueryGroupByTest::GroupByTestHelper()
- QueryGroupByTest::testGroupByAverage in lib/
Drupal/ views/ Tests/ QueryGroupByTest.php - QueryGroupByTest::testGroupByCount in lib/
Drupal/ views/ Tests/ QueryGroupByTest.php - QueryGroupByTest::testGroupByMax in lib/
Drupal/ views/ Tests/ QueryGroupByTest.php - QueryGroupByTest::testGroupByMin in lib/
Drupal/ views/ Tests/ QueryGroupByTest.php - QueryGroupByTest::testGroupBySum in lib/
Drupal/ views/ Tests/ QueryGroupByTest.php
File
- lib/
Drupal/ views/ Tests/ QueryGroupByTest.php, line 68 - Definition of Drupal\views\Tests\QueryGroupByTest.
Class
- QueryGroupByTest
- Tests aggregate functionality of views, for example count.
Namespace
Drupal\views\TestsCode
function GroupByTestHelper($group_by, $values) {
// Create 2 nodes of type1 and 3 nodes of type2
$type1 = $this
->drupalCreateContentType();
$type2 = $this
->drupalCreateContentType();
$node_1 = array(
'type' => $type1->type,
);
// Nids from 1 to 4.
$this
->drupalCreateNode($node_1);
$this
->drupalCreateNode($node_1);
$this
->drupalCreateNode($node_1);
$this
->drupalCreateNode($node_1);
$node_2 = array(
'type' => $type2->type,
);
// Nids from 5 to 7.
$this
->drupalCreateNode($node_2);
$this
->drupalCreateNode($node_2);
$this
->drupalCreateNode($node_2);
$view = $this
->createViewFromConfig('test_group_by_count');
$view->displayHandlers['default']->options['fields']['nid']['group_type'] = $group_by;
$this
->executeView($view);
$this
->assertEqual(count($view->result), 2, 'Make sure the count of items is right.');
// Group by nodetype to identify the right count.
foreach ($view->result as $item) {
$results[$item->node_type] = $item->nid;
}
$this
->assertEqual($results[$type1->type], $values[0]);
$this
->assertEqual($results[$type2->type], $values[1]);
}