You are here

function SelectComplexTest::testHavingCountQuery in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Database/SelectComplexTest.php \Drupal\system\Tests\Database\SelectComplexTest::testHavingCountQuery()

Tests having queries.

File

core/modules/system/src/Tests/Database/SelectComplexTest.php, line 196
Contains \Drupal\system\Tests\Database\SelectComplexTest.

Class

SelectComplexTest
Tests the Select query builder with more complex queries.

Namespace

Drupal\system\Tests\Database

Code

function testHavingCountQuery() {
  $query = db_select('test')
    ->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
    ->groupBy('age')
    ->having('age + 1 > 0');
  $query
    ->addField('test', 'age');
  $query
    ->addExpression('age + 1');
  $count = count($query
    ->execute()
    ->fetchCol());
  $this
    ->assertEqual($count, 4, 'Counted the correct number of records.');
}