Commit 16093b83 authored by catch's avatar catch

Issue #1679570 by sun: Fixed TestBase does not always use the correct database...

Issue #1679570 by sun: Fixed TestBase does not always use the correct database connection for handling assertions.
parent f1cd0a51
......@@ -184,15 +184,7 @@ protected function assert($status, $message = '', $group = 'Other', array $calle
);
// Store assertion for display after the test has completed.
try {
$connection = Database::getConnection('default', 'simpletest_original_default');
}
catch (ConnectionNotDefinedException $e) {
// If the test was not set up, the simpletest_original_default
// connection does not exist.
$connection = Database::getConnection('default', 'default');
}
$connection
self::getDatabaseConnection()
->insert('simpletest')
->fields($assertion)
->execute();
......@@ -246,7 +238,8 @@ public static function insertAssert($test_id, $test_class, $status, $message = '
'file' => $caller['file'],
);
return db_insert('simpletest')
return self::getDatabaseConnection()
->insert('simpletest')
->fields($assertion)
->execute();
}
......@@ -262,11 +255,30 @@ public static function insertAssert($test_id, $test_class, $status, $message = '
* @see Drupal\simpletest\TestBase::insertAssert()
*/
public static function deleteAssert($message_id) {
return (bool) db_delete('simpletest')
return (bool) self::getDatabaseConnection()
->delete('simpletest')
->condition('message_id', $message_id)
->execute();
}
/**
* Returns the database connection to the site running Simpletest.
*
* @return Drupal\Core\Database\Connection
* The database connection to use for inserting assertions.
*/
public static function getDatabaseConnection() {
try {
$connection = Database::getConnection('default', 'simpletest_original_default');
}
catch (ConnectionNotDefinedException $e) {
// If the test was not set up, the simpletest_original_default
// connection does not exist.
$connection = Database::getConnection('default', 'default');
}
return $connection;
}
/**
* Cycles through backtrace until the first non-assertion method is found.
*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment