diff --git a/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php b/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php index 6b83943844..fb1e4f4765 100644 --- a/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php +++ b/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php @@ -17,48 +17,14 @@ class_alias('Drupal\Tests\Listeners\Legacy\HtmlOutputPrinter', 'Drupal\Tests\Lis * Defines a class for providing html output results for functional tests. */ class HtmlOutputPrinter extends ResultPrinter { - - /** - * File to write html links to. - * - * @var string - */ - protected $browserOutputFile; - + use HtmlOutputPrinterTrait; /** * {@inheritdoc} */ public function __construct($out = NULL, $verbose = FALSE, $colors = self::COLOR_DEFAULT, $debug = FALSE, $numberOfColumns = 80, $reverse = FALSE) { parent::__construct($out, $verbose, $colors, $debug, $numberOfColumns, $reverse); - if ($html_output_directory = getenv('BROWSERTEST_OUTPUT_DIRECTORY')) { - // Initialize html output debugging. - $html_output_directory = rtrim($html_output_directory, '/'); - - // Check if directory exists. - 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 { - // 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'); - } + $this->setUpHtmlOutput(); } /** @@ -67,16 +33,7 @@ public function __construct($out = NULL, $verbose = FALSE, $colors = self::COLOR public function printResult(TestResult $result) { parent::printResult($result); - 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); - } - // No need to keep the file around any more. - unlink($this->browserOutputFile); - } + $this->printHtmlOutput(); } } diff --git a/core/tests/Drupal/Tests/Listeners/Legacy/HtmlOutputPrinter.php b/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinterTrait.php similarity index 83% copy from core/tests/Drupal/Tests/Listeners/Legacy/HtmlOutputPrinter.php copy to core/tests/Drupal/Tests/Listeners/HtmlOutputPrinterTrait.php index 2f5c38456b..0a9cc42dc6 100644 --- a/core/tests/Drupal/Tests/Listeners/Legacy/HtmlOutputPrinter.php +++ b/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinterTrait.php @@ -1,11 +1,11 @@ browserOutputFile) { $contents = file_get_contents($this->browserOutputFile); if ($contents) { diff --git a/core/tests/Drupal/Tests/Listeners/Legacy/HtmlOutputPrinter.php b/core/tests/Drupal/Tests/Listeners/Legacy/HtmlOutputPrinter.php index 2f5c38456b..e5abb6ffc6 100644 --- a/core/tests/Drupal/Tests/Listeners/Legacy/HtmlOutputPrinter.php +++ b/core/tests/Drupal/Tests/Listeners/Legacy/HtmlOutputPrinter.php @@ -2,52 +2,21 @@ namespace Drupal\Tests\Listeners\Legacy; +use Drupal\Tests\Listeners\HtmlOutputPrinterTrait; + /** * Defines a class for providing html output results for functional tests. */ class HtmlOutputPrinter extends \PHPUnit_TextUI_ResultPrinter { - - /** - * File to write html links to. - * - * @var string - */ - protected $browserOutputFile; + use HtmlOutputPrinterTrait; /** * {@inheritdoc} */ public function __construct($out, $verbose, $colors, $debug, $numberOfColumns) { parent::__construct($out, $verbose, $colors, $debug, $numberOfColumns); - if ($html_output_directory = getenv('BROWSERTEST_OUTPUT_DIRECTORY')) { - // Initialize html output debugging. - $html_output_directory = rtrim($html_output_directory, '/'); - - // Check if directory exists. - 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 { - // 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'); - } + $this->setUpHtmlOutput(); } /** @@ -56,16 +25,7 @@ public function __construct($out, $verbose, $colors, $debug, $numberOfColumns) { public function printResult(\PHPUnit_Framework_TestResult $result) { parent::printResult($result); - 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); - } - // No need to keep the file around any more. - unlink($this->browserOutputFile); - } + $this->printHtmlOutput(); } }