From ee70cee8442383698f8f146910d5dcbb32bdf054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= Date: Tue, 18 Sep 2012 11:33:38 +0200 Subject: [PATCH] MDL-35506 test if error in transaction forces rollback --- lib/dml/tests/dml_test.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/dml/tests/dml_test.php b/lib/dml/tests/dml_test.php index 11e53bca608..1260e03149e 100644 --- a/lib/dml/tests/dml_test.php +++ b/lib/dml/tests/dml_test.php @@ -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();