MDL-35506 test if error in transaction forces rollback

This commit is contained in:
Petr Škoda 2012-09-18 11:33:38 +02:00
parent a3ab18c735
commit ee70cee844

View File

@ -4186,6 +4186,35 @@ class dml_testcase extends database_driver_testcase {
$this->assertEquals(1, $DB->count_records($tablename));
}
function test_transaction_ignore_error_trouble() {
$DB = $this->tdb;
$dbman = $DB->get_manager();
$table = $this->get_test_table();
$tablename = $table->getName();
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('course', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_index('course', XMLDB_INDEX_UNIQUE, array('course'));
$dbman->create_table($table);
$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->insert_record($tablename, (object)array('course'=>1));
} 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());
}
function test_onelevel_rollback() {
$DB = $this->tdb;
$dbman = $DB->get_manager();