public function QueryGroupByTest::testAggregateCount in Views (for Drupal 7) 8.3
Tests aggregate count feature.
File
- lib/
Drupal/ views/ Tests/ QueryGroupByTest.php, line 26 - Definition of Drupal\views\Tests\QueryGroupByTest.
Class
- QueryGroupByTest
- Tests aggregate functionality of views, for example count.
Namespace
Drupal\views\TestsCode
public function testAggregateCount() {
// Create 2 nodes of type1 and 3 nodes of type2
$type1 = $this
->drupalCreateContentType();
$type2 = $this
->drupalCreateContentType();
$node_1 = array(
'type' => $type1->type,
);
$this
->drupalCreateNode($node_1);
$this
->drupalCreateNode($node_1);
$this
->drupalCreateNode($node_1);
$this
->drupalCreateNode($node_1);
$node_2 = array(
'type' => $type2->type,
);
$this
->drupalCreateNode($node_2);
$this
->drupalCreateNode($node_2);
$this
->drupalCreateNode($node_2);
$view = $this
->createViewFromConfig('test_aggregate_count');
$this
->executeView($view);
$this
->assertEqual(count($view->result), 2, 'Make sure the count of items is right.');
$types = array();
foreach ($view->result as $item) {
// num_records is a alias for nid.
$types[$item->node_type] = $item->num_records;
}
$this
->assertEqual($types[$type1->type], 4);
$this
->assertEqual($types[$type2->type], 3);
}