function MergeTest::testMergeUpdateExcept in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/Database/MergeTest.php \Drupal\system\Tests\Database\MergeTest::testMergeUpdateExcept()
Confirms that we can merge-update a record successfully.
This test varies from the previous test because it manually defines which fields are inserted, and which fields are updated.
File
- core/
modules/ system/ src/ Tests/ Database/ MergeTest.php, line 76 - Contains \Drupal\system\Tests\Database\MergeTest.
Class
- MergeTest
- Tests the MERGE query builder.
Namespace
Drupal\system\Tests\DatabaseCode
function testMergeUpdateExcept() {
$num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')
->fetchField();
db_merge('test_people')
->key('job', 'Speaker')
->insertFields(array(
'age' => 31,
))
->updateFields(array(
'name' => 'Tiffany',
))
->execute();
$num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')
->fetchField();
$this
->assertEqual($num_records_before, $num_records_after, 'Merge updated properly.');
$person = db_query('SELECT * FROM {test_people} WHERE job = :job', array(
':job' => 'Speaker',
))
->fetch();
$this
->assertEqual($person->name, 'Tiffany', 'Name set correctly.');
$this
->assertEqual($person->age, 30, 'Age skipped correctly.');
$this
->assertEqual($person->job, 'Speaker', 'Job set correctly.');
}