diff options
Diffstat (limited to 'modules/simpletest/drupal_web_test_case.php')
-rw-r--r-- | modules/simpletest/drupal_web_test_case.php | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php index a6afcde32..6df78fbf2 100644 --- a/modules/simpletest/drupal_web_test_case.php +++ b/modules/simpletest/drupal_web_test_case.php @@ -138,20 +138,27 @@ abstract class DrupalTestCase { } /** - * Make assertions from outside the test case. + * Store an assertion from outside the testing context. + * + * This is useful for inserting assertions that can only be recorded after + * the test case has been destroyed, such as PHP fatal errors. The caller + * information is not automatically gathered since the caller is most likely + * inserting the assertion on behalf of other code. In all other respects + * the method behaves just like DrupalTestCase::assert() in terms of storing + * the assertion. * * @see DrupalTestCase::assert() */ - public static function assertStatic($test_id, $test_class, $status, $message = '', $group = 'Other', array $caller = NULL) { + public static function insertAssert($test_id, $test_class, $status, $message = '', $group = 'Other', array $caller = array()) { // Convert boolean status to string status. if (is_bool($status)) { $status = $status ? 'pass' : 'fail'; } $caller += array( - 'function' => t('N/A'), - 'line' => -1, - 'file' => t('N/A'), + 'function' => t('Unknown'), + 'line' => 0, + 'file' => t('Unknown'), ); $assertion = array( @@ -1033,13 +1040,22 @@ class DrupalWebTestCase extends DrupalTestCase { ->execute(); $db_prefix = $db_prefix_new; + // Create test directory ahead of installation so fatal errors and debug + // information can be logged during installation process. + $directory = $this->originalFileDirectory . '/simpletest/' . substr($db_prefix, 10); + file_check_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); + + // Log fatal errors. + ini_set('log_errors', 1); + ini_set('error_log', $directory . '/error.log'); + include_once DRUPAL_ROOT . '/includes/install.inc'; drupal_install_system(); $this->preloadRegistry(); // Include the default profile - require_once("./profiles/default/default.profile"); + require_once('./profiles/default/default.profile'); $profile_details = install_profile_info('default', 'en'); // Add the specified modules to the list of modules in the default profile. @@ -1090,15 +1106,9 @@ class DrupalWebTestCase extends DrupalTestCase { // default mail handler. variable_set('smtp_library', drupal_get_path('module', 'simpletest') . '/drupal_web_test_case.php'); - // Use temporary files directory with the same prefix as database. - variable_set('file_directory_path', $this->originalFileDirectory . '/simpletest/' . substr($db_prefix, 10)); - $directory = file_directory_path(); - // Create the files directory. - file_check_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); - - // Log fatal errors. - ini_set('log_errors', 1); - ini_set('error_log', $directory . '/error.log'); + // Use temporary files directory with the same prefix as database. The + // directory will have been created already. + variable_set('file_directory_path', $directory); set_time_limit($this->timeLimit); } @@ -1138,6 +1148,13 @@ class DrupalWebTestCase extends DrupalTestCase { protected function tearDown() { global $db_prefix, $user, $language; + // In case a fatal error occured that was not in the test process read the + // log to pick up any fatal errors. + $db_prefix_temp = $db_prefix; + $db_prefix = $this->originalPrefix; + simpletest_log_read($this->testId, $db_prefix, get_class($this), TRUE); + $db_prefix = $db_prefix_temp; + $emailCount = count(variable_get('simpletest_emails', array())); if ($emailCount) { $message = format_plural($emailCount, t('!count e-mail was sent during this test.'), t('!count e-mails were sent during this test.'), array('!count' => $emailCount)); |