You are here

function DatabaseMergeTestCase::testMergeInsertWithoutUpdate in SimpleTest 7

Test that we can merge-insert without any update fields.

File

tests/database_test.test, line 1120

Class

DatabaseMergeTestCase
Test the MERGE query builder.

Code

function testMergeInsertWithoutUpdate() {
  $num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')
    ->fetchField();
  db_merge('test_people')
    ->key(array(
    'job' => 'Presenter',
  ))
    ->execute();
  $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')
    ->fetchField();
  $this
    ->assertEqual($num_records_before + 1, $num_records_after, t('Merge inserted properly.'));
  $person = db_query('SELECT * FROM {test_people} WHERE job = :job', array(
    ':job' => 'Presenter',
  ))
    ->fetch();
  $this
    ->assertEqual($person->name, '', t('Name set correctly.'));
  $this
    ->assertEqual($person->age, 0, t('Age set correctly.'));
  $this
    ->assertEqual($person->job, 'Presenter', t('Job set correctly.'));
}