commit cc13cb69e7dee0b96c32cd5feff2230c889963b1 Author: Lee Rowlands Date: Thu Mar 24 08:50:58 2016 +1000 p20 diff --git a/core/modules/simpletest/src/BrowserTestBase.php b/core/modules/simpletest/src/BrowserTestBase.php index c7accc8..067ca43 100644 --- a/core/modules/simpletest/src/BrowserTestBase.php +++ b/core/modules/simpletest/src/BrowserTestBase.php @@ -12,6 +12,7 @@ use Behat\Mink\Exception\Exception; use Behat\Mink\Mink; use Behat\Mink\Session; +use Drupal\Component\Utility\Html; use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Cache\Cache; @@ -255,6 +256,13 @@ protected $verboseCounter = 1; /** + * Verbose output enabled. + * + * @var bool + */ + protected $verboseOutput = FALSE; + + /** * Initializes Mink sessions. */ protected function initMink() { @@ -390,9 +398,12 @@ protected function setUp() { } } } + + $verbose_directory = getenv('SIMPLETEST_VERBOSE_DIRECTORY'); + $this->verboseOutput = (bool) $verbose_directory; $this->verboseClassName = str_replace("\\", "_", get_called_class()); - $this->verboseDirectory = sys_get_temp_dir() . '/verbose'; - $this->verboseCounterStorage = sys_get_temp_dir() . '/verbose/' . $this->verboseClassName . '.counter'; + $this->verboseDirectory = rtrim($verbose_directory, '/'); + $this->verboseCounterStorage = $this->verboseDirectory . '/' . $this->verboseClassName . '.counter'; if (is_file($this->verboseCounterStorage)) { $this->verboseCounter = max(1, (int) file_get_contents($this->verboseCounterStorage)); } @@ -534,11 +545,13 @@ protected function drupalGet($path, array $options = array()) { // Ensure that any changes to variables in the other thread are picked up. $this->refreshVariables(); - $verbose = 'GET request to: ' . $url . - '
Ending URL: ' . $this->getSession()->getCurrentUrl(); - $verbose .= '
' . $out; - - $this->verbose($verbose); + if ($this->verboseOutput) { + $verbose = 'GET request to: ' . $url . + '
Ending URL: ' . $this->getSession()->getCurrentUrl(); + $verbose .= '
' . $out; + $verbose .= $this->getVerboseHeaders(); + $this->verbose($verbose); + } return $out; } @@ -825,12 +838,14 @@ protected function submitForm(array $edit, $submit, $form_html_id = NULL) { // Ensure that any changes to variables in the other thread are picked up. $this->refreshVariables(); - $out = $this->getSession()->getPage()->getContent(); - $verbose = 'POST request to: ' . $action . - '
Ending URL: ' . $this->getSession()->getCurrentUrl(); - $verbose .= '
' . $out; - - $this->verbose($verbose); + if ($this->verboseOutput) { + $out = $this->getSession()->getPage()->getContent(); + $verbose = 'POST request to: ' . $action . + '
Ending URL: ' . $this->getSession()->getCurrentUrl(); + $verbose .= '
' . $out; + $verbose .= $this->getVerboseHeaders(); + $this->verbose($verbose); + } } /** @@ -1407,10 +1422,25 @@ public function __sleep() { * @see \Drupal\Tests\Listeners\VerbosePrinter::printResult() */ protected function verbose($message) { + if (!$this->verboseOutput) { + return; + } $message = '
ID #' . $this->verboseCounter . ' (Previous | Next)
' . $message; $verbose_filename = $this->verboseClassName . '-' . $this->verboseCounter . '.html'; file_put_contents($this->verboseDirectory . '/' . $verbose_filename, $message); file_put_contents($this->verboseCounterStorage, $this->verboseCounter++); } + /** + * Returns headers in verbose format. + * + * @return string + * Verbose headers. + */ + protected function getVerboseHeaders() { + return '
Headers:
' . Html::escape(var_export(array_map(function($headers) {
+      return implode(';', array_map('trim', $headers));
+    }, $this->getSession()->getResponseHeaders()), TRUE)) . '
'; + } + } diff --git a/core/tests/Drupal/Tests/Listeners/VerbosePrinter.php b/core/tests/Drupal/Tests/Listeners/VerbosePrinter.php index 2f88bb3..ea3483b 100644 --- a/core/tests/Drupal/Tests/Listeners/VerbosePrinter.php +++ b/core/tests/Drupal/Tests/Listeners/VerbosePrinter.php @@ -17,23 +17,25 @@ class VerbosePrinter extends \PHPUnit_TextUI_ResultPrinter { */ public function __construct($out, $verbose, $colors, $debug, $numberOfColumns) { parent::__construct($out, $verbose, $colors, $debug, $numberOfColumns); - // Initialize verbose debugging. - $this->directory = sys_get_temp_dir() . '/verbose'; - // Check if directory exists. - if (is_dir($this->directory)) { - // Remove it. - $this->cleanUpLastTestRun($this->directory); - } - // Create the directory. - if (mkdir($this->directory, 0775)) { - if (is_writable($this->directory)) { - chmod($this->directory, 0775); + if ($verbose_directory = getenv('SIMPLETEST_VERBOSE_DIRECTORY')) { + // Initialize verbose debugging. + $this->directory = rtrim($verbose_directory, '/'); + // Check if directory exists. + if (is_dir($this->directory)) { + // Remove it. + $this->cleanUpLastTestRun($this->directory); + } + // Create the directory. + if (mkdir($this->directory, 0775)) { + if (is_writable($this->directory)) { + chmod($this->directory, 0775); + } + file_put_contents($this->directory . '/.htaccess', "\nExpiresActive Off\n\n"); + } + else { + $this->writeWithColor('bg-red, fg-black', "Verbose directory {$this->directory} could not be created."); + $this->directory = NULL; } - file_put_contents($this->directory . '/.htaccess', "\nExpiresActive Off\n\n"); - } - else { - $this->writeWithColor('bg-red, fg-black', "Verbose directory {$this->directory} could not be created."); - $this->directory = NULL; } } @@ -44,6 +46,12 @@ public function printResult(\PHPUnit_Framework_TestResult $result) { parent::printResult($result); if (!$this->directory) { + $this->writeWithColor('bg-yellow, fg-black', 'No verbose output was generated'); + $this->writeNewLine(); + $this->write('To generate verbose output for functional tests, set the SIMPLETEST_VERBOSE_DIRECTORY environment variable.'); + $this->writeNewLine(); + $this->write('e.g export SIMPLETEST_VERBOSE_DIRECTORY="/path/to/webroot/sites/default/files/simpletest/verbose".'); + $this->writeNewLine(); return; }