function ViewsQueryGroupByTest::testAggregateCount

Tests aggregate count feature.

File

tests/views_groupby.test, line 111

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->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->viewsAggregateCountView();
    $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);
}