function DatabaseDeleteTruncateTestCase::testSimpleDelete

Confirm that we can delete a single record successfully.

File

modules/simpletest/tests/database_test.test, line 1187

Class

DatabaseDeleteTruncateTestCase
Delete/Truncate tests.

Code

function testSimpleDelete() {
    $num_records_before = db_query('SELECT COUNT(*) FROM {test}')->fetchField();
    $num_deleted = db_delete('test')->condition('id', 1)
        ->execute();
    $this->assertIdentical($num_deleted, 1, 'Deleted 1 record.');
    $num_records_after = db_query('SELECT COUNT(*) FROM {test}')->fetchField();
    $this->assertEqual($num_records_before, $num_records_after + $num_deleted, 'Deletion adds up.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.