function HtmlOutputPrinterTrait::setUpHtmlOutput

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Listeners/HtmlOutputPrinterTrait.php \Drupal\Tests\Listeners\HtmlOutputPrinterTrait::setUpHtmlOutput()
  2. 10 core/tests/Drupal/Tests/Listeners/HtmlOutputPrinterTrait.php \Drupal\Tests\Listeners\HtmlOutputPrinterTrait::setUpHtmlOutput()
  3. 11.x core/tests/Drupal/Tests/Listeners/HtmlOutputPrinterTrait.php \Drupal\Tests\Listeners\HtmlOutputPrinterTrait::setUpHtmlOutput()

Creates the file to list the HTML output created during the test.

See also

\Drupal\Tests\BrowserTestBase::initBrowserOutputFile()

1 call to HtmlOutputPrinterTrait::setUpHtmlOutput()
HtmlOutputPrinterTrait::__construct in core/tests/Drupal/Tests/Listeners/HtmlOutputPrinterTrait.php

File

core/tests/Drupal/Tests/Listeners/HtmlOutputPrinterTrait.php, line 35

Class

HtmlOutputPrinterTrait
Defines a class for providing html output results for functional tests.

Namespace

Drupal\Tests\Listeners

Code

protected function setUpHtmlOutput() {
  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');
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.