summaryrefslogtreecommitdiff
path: root/modules/simpletest
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2014-11-02 12:51:07 -0500
committerDavid Rothstein <drothstein@gmail.com>2014-11-02 12:51:07 -0500
commit90d6f05facedd14e6abf39b86bddff5ae1320eed (patch)
treef37cb6b581809d5ee7ddbad3b7da75477a21fe3f /modules/simpletest
parentc684532504121f6342ed4ae97951dc7034dfb82b (diff)
downloadbrdo-90d6f05facedd14e6abf39b86bddff5ae1320eed.tar.gz
brdo-90d6f05facedd14e6abf39b86bddff5ae1320eed.tar.bz2
Issue #1679570 by mgifford, lucascaro, sun: Fixed TestBase does not always use the correct database connection for handling assertions.
Diffstat (limited to 'modules/simpletest')
-rw-r--r--modules/simpletest/drupal_web_test_case.php35
1 files changed, 24 insertions, 11 deletions
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index 2a5aae8a9..39dacfa1d 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -143,15 +143,7 @@ abstract class DrupalTestCase {
);
// Store assertion for display after the test has completed.
- try {
- $connection = Database::getConnection('default', 'simpletest_original_default');
- }
- catch (DatabaseConnectionNotDefinedException $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();
@@ -167,6 +159,25 @@ abstract class DrupalTestCase {
}
/**
+ * Returns the database connection to the site running Simpletest.
+ *
+ * @return DatabaseConnection
+ * The database connection to use for inserting assertions.
+ */
+ public static function getDatabaseConnection() {
+ try {
+ $connection = Database::getConnection('default', 'simpletest_original_default');
+ }
+ catch (DatabaseConnectionNotDefinedException $e) {
+ // If the test was not set up, the simpletest_original_default
+ // connection does not exist.
+ $connection = Database::getConnection('default', 'default');
+ }
+
+ return $connection;
+ }
+
+ /**
* Store an assertion from outside the testing context.
*
* This is useful for inserting assertions that can only be recorded after
@@ -205,7 +216,8 @@ abstract class DrupalTestCase {
'file' => $caller['file'],
);
- return db_insert('simpletest')
+ return self::getDatabaseConnection()
+ ->insert('simpletest')
->fields($assertion)
->execute();
}
@@ -221,7 +233,8 @@ abstract class DrupalTestCase {
* @see DrupalTestCase::insertAssert()
*/
public static function deleteAssert($message_id) {
- return (bool) db_delete('simpletest')
+ return (bool) self::getDatabaseConnection()
+ ->delete('simpletest')
->condition('message_id', $message_id)
->execute();
}