1.20.x views_groupby.test | public ViewsQueryGroupByTest::testAggregateCount() |
Tests aggregate count feature.
File
- modules/
views/ tests/ views_groupby.test, line 18 - Tests aggregate functionality of Views.
Class
- ViewsQueryGroupByTest
- Tests aggregate functionality of views, for example count.
Code
public function testAggregateCount() {
// Create 2 nodes of type1 and 3 nodes of type2
$type1 = $this->backdropCreateContentType();
$type2 = $this->backdropCreateContentType();
$node_1 = array(
'type' => $type1->type,
);
$this->backdropCreateNode($node_1);
$this->backdropCreateNode($node_1);
$this->backdropCreateNode($node_1);
$this->backdropCreateNode($node_1);
$node_2 = array(
'type' => $type2->type,
);
$this->backdropCreateNode($node_2);
$this->backdropCreateNode($node_2);
$this->backdropCreateNode($node_2);
$view = $this->viewsAggregateCountView();
$output = $view->execute_display();
$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);
}