diff --git a/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php
index 2f4cab5..a761213 100644
--- a/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php
+++ b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php
@@ -7,7 +7,7 @@
namespace Drupal\FunctionalJavascriptTests;
-use Drupal\simpletest\BrowserTestBase;
+use Drupal\Tests\BrowserTestBase;
use Symfony\Component\CssSelector\CssSelector;
use Zumba\Mink\Driver\PhantomJSDriver;
diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php
index 9877de7..d7045ec 100644
--- a/core/tests/Drupal/Tests/BrowserTestBase.php
+++ b/core/tests/Drupal/Tests/BrowserTestBase.php
@@ -262,6 +262,17 @@
protected $htmlOutputEnabled = FALSE;
/**
+ * The file name to write the list of URLs to.
+ *
+ * This file is read by the PHPUnit result printer.
+ *
+ * @var string
+ *
+ * @see \Drupal\Tests\Listeners\HtmlOutputPrinter
+ */
+ protected $htmlOutputFile;
+
+ /**
* HTML output test ID.
*
* @var int
@@ -431,14 +442,22 @@ protected function setUp() {
}
}
- $html_output_directory = getenv('BROWSERTEST_OUTPUT_DIRECTORY');
- $this->htmlOutputEnabled = (bool) $html_output_directory;
- $this->htmlOutputClassName = str_replace("\\", "_", get_called_class());
- $this->htmlOutputDirectory = rtrim($html_output_directory, '/');
- $this->htmlOutputCounterStorage = $this->htmlOutputDirectory . '/' . $this->htmlOutputClassName . '.counter';
- $this->htmlOutputTestId = str_replace('sites/simpletest/', '', $this->siteDirectory);
- if (is_file($this->htmlOutputCounterStorage)) {
- $this->htmlOutputCounter = max(1, (int) file_get_contents($this->htmlOutputCounterStorage)) + 1;
+ // Creates the directory to store browser output in if a file to write
+ // URLs to has been created by \Drupal\Tests\Listeners\HtmlOutputPrinter.
+ $browser_output_file = getenv('BROWSERTEST_OUTPUT_FILE');
+ $this->htmlOutputEnabled = is_file($browser_output_file);
+ if ($this->htmlOutputEnabled) {
+ $this->htmlOutputFile = $browser_output_file;
+ $this->htmlOutputClassName = str_replace("\\", "_", get_called_class());
+ $this->htmlOutputDirectory = DRUPAL_ROOT . '/sites/simpletest/browser_output';
+ if (file_prepare_directory($this->htmlOutputDirectory, FILE_CREATE_DIRECTORY) && !file_exists($this->htmlOutputDirectory . '/.htaccess')) {
+ file_put_contents($this->htmlOutputDirectory . '/.htaccess', "\nExpiresActive Off\n\n");
+ }
+ $this->htmlOutputCounterStorage = $this->htmlOutputDirectory . '/' . $this->htmlOutputClassName . '.counter';
+ $this->htmlOutputTestId = str_replace('sites/simpletest/', '', $this->siteDirectory);
+ if (is_file($this->htmlOutputCounterStorage)) {
+ $this->htmlOutputCounter = max(1, (int) file_get_contents($this->htmlOutputCounterStorage)) + 1;
+ }
}
}
@@ -1496,6 +1515,7 @@ protected function htmlOutput($message) {
$html_output_filename = $this->htmlOutputClassName . '-' . $this->htmlOutputCounter . '-' . $this->htmlOutputTestId . '.html';
file_put_contents($this->htmlOutputDirectory . '/' . $html_output_filename, $message);
file_put_contents($this->htmlOutputCounterStorage, $this->htmlOutputCounter++);
+ file_put_contents($this->htmlOutputFile, file_create_url('sites/simpletest/browser_output/' . $html_output_filename) . "\n", FILE_APPEND);
}
/**
@@ -1505,9 +1525,15 @@ protected function htmlOutput($message) {
* HTML output headers.
*/
protected function getHtmlOutputHeaders() {
- return '
Headers: ' . Html::escape(var_export(array_map(function($headers) {
- return implode(';', array_map('trim', $headers));
- }, $this->getSession()->getResponseHeaders()), TRUE)) . '';
+ $headers = array_map(function($headers) {
+ if (is_array($headers)) {
+ return implode(';', array_map('trim', $headers));
+ }
+ else {
+ return $headers;
+ }
+ }, $this->getSession()->getResponseHeaders());
+ return '
Headers: ' . Html::escape(var_export($headers, TRUE)) . '
';
}
}
diff --git a/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php b/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php
index 01f1205..ab1806f 100644
--- a/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php
+++ b/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php
@@ -1,4 +1,5 @@
directory = rtrim($html_output_directory, '/');
+ $html_output_directory = rtrim($html_output_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");
+ if (!is_dir($html_output_directory) || !is_writable($html_output_directory)) {
+ $this->writeWithColor('bg-red, fg-black', "HTML output directory $html_output_directory is not a writable directory.");
}
else {
- $this->writeWithColor('bg-red, fg-black', "HTML output directory {$this->directory} could not be created.");
- $this->directory = NULL;
+ // Convert to a canonicalized absolute pathname just in case the current
+ // working directory is changed.
+ $html_output_directory = realpath($html_output_directory);
+ $this->browserOutputFile = tempnam($html_output_directory, 'browser_output_');
+ if ($this->browserOutputFile) {
+ touch($this->browserOutputFile);
+ }
+ else {
+ $this->writeWithColor('bg-red, fg-black', "Unable to create a temporary file in $html_output_directory.");
+ }
}
}
+
+ if ($this->browserOutputFile) {
+ putenv('BROWSERTEST_OUTPUT_FILE=' . $this->browserOutputFile);
+ }
+ else {
+ // Remove any environment variable.
+ putenv('BROWSERTEST_OUTPUT_FILE');
+ }
}
/**
@@ -51,53 +61,15 @@ public function __construct($out, $verbose, $colors, $debug, $numberOfColumns) {
public function printResult(\PHPUnit_Framework_TestResult $result) {
parent::printResult($result);
- if (!$this->directory) {
- $this->writeWithColor('bg-yellow, fg-black', 'No HTML output was generated');
- $this->writeNewLine();
- $this->write('To generate HTML output for functional tests, set the BROWSERTEST_OUTPUT_DIRECTORY environment variable.');
- $this->writeNewLine();
- $this->write('e.g export BROWSERTEST_OUTPUT_DIRECTORY="/path/to/webroot/sites/default/files/simpletest/verbose".');
- $this->writeNewLine();
- return;
- }
-
- $counter = 0;
- foreach (glob($this->directory . '/*.html') as $filename) {
- if (!$counter) {
+ if ($this->browserOutputFile) {
+ $contents = file_get_contents($this->browserOutputFile);
+ if ($contents) {
$this->writeNewLine();
$this->writeWithColor('bg-yellow, fg-black', 'HTML output was generated');
+ $this->write($contents);
}
- $this->write($filename);
- $this->writeNewLine();
- $counter++;
- }
- if ($counter) {
- $this->writeWithColor('bg-yellow, fg-black', sprintf('%d HTML output files', $counter));
- }
- }
-
- /**
- * Cleans up last run.
- *
- * @param string $directory
- * Directory to remove.
- */
- protected function cleanUpLastTestRun($directory) {
- if (isset($directory) && is_dir($directory)) {
- $objects = scandir($directory);
- foreach ($objects as $object) {
- if ($object !== "." && $object !== "..") {
- $filename = $directory . "/" . $object;
- if (filetype($filename) == "directory") {
- $this->cleanUpLastTestRun($filename);
- }
- else {
- unlink($filename);
- }
- }
- }
- reset($objects);
- rmdir($directory);
+ // No need to keep the file around any more.
+ unlink($this->browserOutputFile);
}
}