You are here

function DatabaseMergeTestCase::testMergeUpdateWithoutUpdate in SimpleTest 7

Confirm that we can merge-update without any update fields.

File

tests/database_test.test, line 1139

Class

DatabaseMergeTestCase
Test the MERGE query builder.

Code

function testMergeUpdateWithoutUpdate() {
  $num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')
    ->fetchField();
  db_merge('test_people')
    ->key(array(
    'job' => 'Speaker',
  ))
    ->execute();
  $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')
    ->fetchField();
  $this
    ->assertEqual($num_records_before, $num_records_after, t('Merge skipped properly.'));
  $person = db_query('SELECT * FROM {test_people} WHERE job = :job', array(
    ':job' => 'Speaker',
  ))
    ->fetch();
  $this
    ->assertEqual($person->name, 'Meredith', t('Name skipped correctly.'));
  $this
    ->assertEqual($person->age, 30, t('Age skipped correctly.'));
  $this
    ->assertEqual($person->job, 'Speaker', t('Job skipped correctly.'));
  db_merge('test_people')
    ->key(array(
    'job' => 'Speaker',
  ))
    ->fields(array(
    'age' => 31,
  ))
    ->updateExcept(array(
    'age',
  ))
    ->execute();
  $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')
    ->fetchField();
  $this
    ->assertEqual($num_records_before, $num_records_after, t('Merge skipped properly.'));
  $person = db_query('SELECT * FROM {test_people} WHERE job = :job', array(
    ':job' => 'Speaker',
  ))
    ->fetch();
  $this
    ->assertEqual($person->name, 'Meredith', t('Name skipped correctly.'));
  $this
    ->assertEqual($person->age, 30, t('Age skipped correctly.'));
  $this
    ->assertEqual($person->job, 'Speaker', t('Job skipped correctly.'));
}