function QueryGroupByTest::testAggregateCount

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Kernel/QueryGroupByTest.php \Drupal\Tests\views\Kernel\QueryGroupByTest::testAggregateCount()
  2. 8.9.x core/modules/views/tests/src/Kernel/QueryGroupByTest.php \Drupal\Tests\views\Kernel\QueryGroupByTest::testAggregateCount()
  3. 10 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 70

Class

QueryGroupByTest
Tests aggregate functionality of views, for example count.

Namespace

Drupal\Tests\views\Kernel

Code

public function testAggregateCount() : void {
  $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 an alias for id.
    $types[$item->entity_test_name] = $item->num_records;
  }
  $this->assertEquals(4, $types['name1']);
  $this->assertEquals(3, $types['name2']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.