public function QueryGroupByTest::testAggregateCount in Drupal 8
Same name and namespace in other branches
- 9 core/modules/views/tests/src/Kernel/QueryGroupByTest.php \Drupal\Tests\views\Kernel\QueryGroupByTest::testAggregateCount()
Tests aggregate count feature.
File
- core/
modules/ views/ tests/ src/ Kernel/ QueryGroupByTest.php, line 64
Class
- QueryGroupByTest
- Tests aggregate functionality of views, for example count.
Namespace
Drupal\Tests\views\KernelCode
public function testAggregateCount() {
$this
->setupTestEntities();
$view = Views::getView('test_aggregate_count');
$this
->executeView($view);
$this
->assertCount(2, $view->result, 'Make sure the count of items is right.');
$types = [];
foreach ($view->result as $item) {
// num_records is a alias for id.
$types[$item->entity_test_name] = $item->num_records;
}
$this
->assertEqual($types['name1'], 4, 'Groupby the name: name1 returned the expected amount of results.');
$this
->assertEqual($types['name2'], 3, 'Groupby the name: name2 returned the expected amount of results.');
}