You are here

function SelectTest::testUnionCount in Zircon Profile 8

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

Tests that we can get a count query for a UNION Select query.

File

core/modules/system/src/Tests/Database/SelectTest.php, line 311
Contains \Drupal\system\Tests\Database\SelectTest.

Class

SelectTest
Tests the Select query builder.

Namespace

Drupal\system\Tests\Database

Code

function testUnionCount() {
  $query_1 = db_select('test', 't')
    ->fields('t', array(
    'name',
    'age',
  ))
    ->condition('age', array(
    27,
    28,
  ), 'IN');
  $query_2 = db_select('test', 't')
    ->fields('t', array(
    'name',
    'age',
  ))
    ->condition('age', 28);
  $query_1
    ->union($query_2, 'ALL');
  $names = $query_1
    ->execute()
    ->fetchCol();
  $query_3 = $query_1
    ->countQuery();
  $count = $query_3
    ->execute()
    ->fetchField();

  // Ensure the counts match.
  $this
    ->assertEqual(count($names), $count, "The count query's result matched the number of rows in the UNION query.");
}