X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Ftests%2FDrupal%2FTests%2FListeners%2FHtmlOutputPrinterTrait.php;fp=web%2Fcore%2Ftests%2FDrupal%2FTests%2FListeners%2FHtmlOutputPrinterTrait.php;h=1dd67eb9e9a3e5367594d3049c3865ad2d1e3353;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinterTrait.php b/web/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinterTrait.php new file mode 100644 index 000000000..1dd67eb9e --- /dev/null +++ b/web/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinterTrait.php @@ -0,0 +1,72 @@ +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'); + } + } + + /** + * Prints the list of HTML output generated during the test. + */ + protected function printHtmlOutput() { + 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); + } + } + +}