Skip to content

Commit

Permalink
MDL-35506 add more transaction error tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Sep 26, 2012
1 parent bedd098 commit d719d59
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions lib/dml/tests/dml_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4199,6 +4199,7 @@ function test_transaction_ignore_error_trouble() {
$table->add_index('course', XMLDB_INDEX_UNIQUE, array('course'));
$dbman->create_table($table);

// Test error on SQL_QUERY_INSERT.
$transaction = $DB->start_delegated_transaction();
$this->assertEquals(0, $DB->count_records($tablename));
$DB->insert_record($tablename, (object)array('course'=>1));
Expand All @@ -4213,6 +4214,59 @@ function test_transaction_ignore_error_trouble() {
$transaction->allow_commit();
$this->assertEquals(2, $DB->count_records($tablename));
$this->assertFalse($DB->is_transaction_started());

// Test error on SQL_QUERY_SELECT.
$DB->delete_records($tablename);
$transaction = $DB->start_delegated_transaction();
$this->assertEquals(0, $DB->count_records($tablename));
$DB->insert_record($tablename, (object)array('course'=>1));
$this->assertEquals(1, $DB->count_records($tablename));
try {
$DB->get_records_sql('s e l e c t');
} catch (Exception $e) {
// This must be ignored and it must not roll back the whole transaction.
}
$DB->insert_record($tablename, (object)array('course'=>2));
$this->assertEquals(2, $DB->count_records($tablename));
$transaction->allow_commit();
$this->assertEquals(2, $DB->count_records($tablename));
$this->assertFalse($DB->is_transaction_started());

// Test error on structure SQL_QUERY_UPDATE.
$DB->delete_records($tablename);
$transaction = $DB->start_delegated_transaction();
$this->assertEquals(0, $DB->count_records($tablename));
$DB->insert_record($tablename, (object)array('course'=>1));
$this->assertEquals(1, $DB->count_records($tablename));
try {
$DB->execute('xxxx');
} catch (Exception $e) {
// This must be ignored and it must not roll back the whole transaction.
}
$DB->insert_record($tablename, (object)array('course'=>2));
$this->assertEquals(2, $DB->count_records($tablename));
$transaction->allow_commit();
$this->assertEquals(2, $DB->count_records($tablename));
$this->assertFalse($DB->is_transaction_started());

// Test error on structure SQL_QUERY_STRUCTURE.
$DB->delete_records($tablename);
$transaction = $DB->start_delegated_transaction();
$this->assertEquals(0, $DB->count_records($tablename));
$DB->insert_record($tablename, (object)array('course'=>1));
$this->assertEquals(1, $DB->count_records($tablename));
try {
$DB->change_database_structure('xxxx');
} catch (Exception $e) {
// This must be ignored and it must not roll back the whole transaction.
}
$DB->insert_record($tablename, (object)array('course'=>2));
$this->assertEquals(2, $DB->count_records($tablename));
$transaction->allow_commit();
$this->assertEquals(2, $DB->count_records($tablename));
$this->assertFalse($DB->is_transaction_started());

// NOTE: SQL_QUERY_STRUCTURE is intentionally not tested here because it should never fail.
}

function test_onelevel_rollback() {
Expand Down

0 comments on commit d719d59

Please sign in to comment.