Skip to content
Snippets Groups Projects
Commit 16093b83 authored by catch's avatar catch
Browse files

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
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment