diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php index 794054d..ca3abf6 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -91,6 +91,36 @@ abstract class TestBase { protected $setupEnvironment = FALSE; /** + * TRUE if verbose debugging is enabled. + * + * @var boolean + */ + protected $verbose = FALSE; + + /** + * Incrementing identifier for verbose output filenames. + * + * @var integer + */ + protected $verboseId = 0; + + /** + * Safe class name for use in verbose output filenames. + * + * Namespaces separator (\) replaced with _. + * + * @var string + */ + protected $verboseClassName; + + /** + * Directory where verbose output files are put. + * + * @var string + */ + protected $verboseDirectory; + + /** * Constructor for Test. * * @param $test_id @@ -457,11 +487,21 @@ abstract class TestBase { * @see simpletest_verbose() */ protected function verbose($message) { - if ($id = simpletest_verbose($message)) { - $class = str_replace('\\', '_', get_class($this)); - $url = file_create_url($this->originalFileDirectory . '/simpletest/verbose/' . $class . '-' . $id . '.html'); - $this->error(l(t('Verbose message'), $url, array('attributes' => array('target' => '_blank'))), 'User notice'); + // Do nothing if verbose debugging is disabled. + if (!$this->verbose) { + return; + } + + $message = '
ID #' . $this->verboseId . ' (Previous | Next)
' . $message; + $verbose_filename = $this->verboseDirectory . '/' . $this->verboseClassName . '-' . $this->verboseId . '.html'; + if (file_put_contents($verbose_filename, $message, FILE_APPEND)) { + $url = file_create_url($this->originalFileDirectory . '/simpletest/verbose/' . $this->verboseClassName . '-' . $this->verboseId . '.html'); + // Not using l() to avoid invoking the theme system, so that unit tests + // can use verbose() as well. + $url = '' . t('Verbose message') . ''; + $this->error($url, 'User notice'); } + $this->verboseId++; } /** @@ -477,10 +517,16 @@ abstract class TestBase { * methods during debugging. */ public function run(array $methods = array()) { - // Initialize verbose debugging. $class = get_class($this); - simpletest_verbose(NULL, variable_get('file_public_path', conf_path() . '/files'), str_replace('\\', '_', $class)); - + if (variable_get('simpletest_verbose', TRUE)) { + // Initialize verbose debugging. + $this->verbose = TRUE; + $this->verboseDirectory = variable_get('file_public_path', conf_path() . '/files') . '/simpletest/verbose'; + if (file_prepare_directory($this->verboseDirectory, FILE_CREATE_DIRECTORY) && !file_exists($this->verboseDirectory . '/.htaccess')) { + file_put_contents($this->verboseDirectory . '/.htaccess', "\nExpiresActive Off\n\n"); + } + $this->verboseClassName = str_replace("\\", "_", $class); + } // HTTP auth settings (:) for the simpletest browser // when sending requests to the test site. $this->httpauth_method = variable_get('simpletest_httpauth_method', CURLAUTH_BASIC); diff --git a/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php index d54912a..98ed71d 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php @@ -55,12 +55,6 @@ abstract class UnitTestBase extends TestBase { // Enforce an empty module list. module_list(NULL, array()); - // Re-implant theme registry. - // Required for l() and other functions to work correctly and not trigger - // database lookups. - $theme_get_registry = &drupal_static('theme_get_registry'); - $theme_get_registry[FALSE] = $this->originalThemeRegistry; - $conf['file_public_path'] = $this->public_files_directory; // Change the database prefix. diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index 38c360b..4138916 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -566,51 +566,3 @@ function simpletest_mail_alter(&$message) { $message['send'] = FALSE; } } - -/** - * Logs verbose message in a text file. - * - * If verbose mode is enabled then page requests will be dumped to a file and - * presented on the test result screen. The messages will be placed in a file - * located in the simpletest directory in the original file system. - * - * @param $message - * The verbose message to be stored. - * @param $original_file_directory - * The original file directory, before it was changed for testing purposes. - * @param $test_class - * The active test case class. - * - * @return - * The ID of the message to be placed in related assertion messages. - * - * @see Drupal\simpletest\TestBase->originalFileDirectory() - * @see Drupal\simpletest\WebTestBase->verbose() - */ -function simpletest_verbose($message, $original_file_directory = NULL, $test_class = NULL) { - static $file_directory = NULL, $class = NULL, $id = 1, $verbose = NULL; - - // Will pass first time during setup phase, and when verbose is TRUE. - if (!isset($original_file_directory) && !$verbose) { - return FALSE; - } - - if ($message && $file_directory) { - $message = '
ID #' . $id . ' (Previous | Next)
' . $message; - file_put_contents($file_directory . "/simpletest/verbose/$class-$id.html", $message, FILE_APPEND); - return $id++; - } - - if ($original_file_directory) { - $file_directory = $original_file_directory; - $class = $test_class; - $verbose = variable_get('simpletest_verbose', TRUE); - $directory = $file_directory . '/simpletest/verbose'; - $writable = file_prepare_directory($directory, FILE_CREATE_DIRECTORY); - if ($writable && !file_exists($directory . '/.htaccess')) { - file_put_contents($directory . '/.htaccess', "\nExpiresActive Off\n\n"); - } - return $writable; - } - return FALSE; -}