From 4a99df11e9dead2d61bfcc2d8a06d7f78ebefe1a Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Tue, 20 Jan 2009 03:54:15 +0000 Subject: #355225 by Josh Waihi and Damien Tournoud: Fix inconsistent behaviour with transaction support and insert queries. All tests should pass on PostgreSQL now. Woot! :) --- modules/simpletest/tests/database_test.test | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'modules/simpletest/tests/database_test.test') diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test index 8451f83f1..589de9600 100644 --- a/modules/simpletest/tests/database_test.test +++ b/modules/simpletest/tests/database_test.test @@ -2047,19 +2047,35 @@ class DatabaseInvalidDataTestCase extends DatabaseTestCase { 'job' => 'Singer', )) ->execute(); - $this->assertTrue(FALSE, t('Insert succeedded when it should not have.')); + $this->fail(t('Insert succeedded when it should not have.')); } catch (Exception $e) { - // Check the first record was inserted. - $result = db_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 63)); - $this->assertIdentical($result->fetchField(), 'Elvis', t('First record inserted as expected.')); + // Check if the first record was inserted. + $name = db_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 63))->fetchField(); + + if ($name == 'Elvis') { + if (!Database::getActiveConnection()->supportsTransactions()) { + // This is an expected fail. + // Database engines that don't support transactions can leave partial + // inserts in place when an error occurs. This is the case for MySQL + // when running on a MyISAM table. + $this->pass(t("The whole transaction has not been rolled-back when a duplicate key insert occurs, this is expected because the database doesn't support transactions")); + } + else { + $this->fail(t('The whole transaction is rolled back when a duplicate key insert occurs.')); + } + } + else { + $this->pass(t('The whole transaction is rolled back when a duplicate key insert occurs.')); + } // Ensure the other values were not inserted. $record = db_select('test') ->fields('test', array('name', 'age')) ->condition('age', array(17, 75),'IN') ->execute()->fetchObject(); - $this->assertFalse($record, t('Insert aborted as expected.')); + + $this->assertFalse($record, t('The rest of the insert aborted as expected.')); } } -- cgit v1.2.3