You are here

function DatabaseSelectTestCase::testUnionAll in SimpleTest 7

Test that we can UNION ALL multiple Select queries together.

File

tests/database_test.test, line 1387

Class

DatabaseSelectTestCase
Test the SELECT builder.

Code

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

  // Ensure we get all 3 records.
  $this
    ->assertEqual(count($names), 3, t('UNION ALL correctly preserved duplicates.'));
  $this
    ->assertEqual($names[0], 'George', t('First query returned correct first name.'));
  $this
    ->assertEqual($names[1], 'Ringo', t('Second query returned correct second name.'));
  $this
    ->assertEqual($names[2], 'Ringo', t('Third query returned correct name.'));
}