You are here

protected function BrowserHtmlDebugTrait::initBrowserOutputFile in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php \Drupal\Tests\BrowserHtmlDebugTrait::initBrowserOutputFile()

Creates the directory to store browser output.

Creates the directory to store browser output in if a file to write URLs to has been created by \Drupal\Tests\Listeners\HtmlOutputPrinter.

4 calls to BrowserHtmlDebugTrait::initBrowserOutputFile()
BrowserTestBase::setUp in core/tests/Drupal/Tests/BrowserTestBase.php
InstallerExistingSettingsReadOnlyMismatchProfileTest::testInstalled in core/tests/Drupal/FunctionalTests/Installer/InstallerExistingSettingsReadOnlyMismatchProfileTest.php
Verifies that installation succeeded.
InstallerTestBase::setUp in core/tests/Drupal/FunctionalTests/Installer/InstallerTestBase.php
UpdatePathTestBase::setUp in core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php
Overrides WebTestBase::setUp() for update testing.

File

core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php, line 138

Class

BrowserHtmlDebugTrait
Provides the debug functions for browser tests.

Namespace

Drupal\Tests

Code

protected function initBrowserOutputFile() {
  $browser_output_file = getenv('BROWSERTEST_OUTPUT_FILE');
  $this->htmlOutputEnabled = is_file($browser_output_file);
  $this->htmlOutputBaseUrl = getenv('BROWSERTEST_OUTPUT_BASE_URL') ?: $GLOBALS['base_url'];
  if ($this->htmlOutputEnabled) {
    $this->htmlOutputFile = $browser_output_file;
    $this->htmlOutputClassName = str_replace("\\", "_", get_called_class());
    $this->htmlOutputDirectory = DRUPAL_ROOT . '/sites/simpletest/browser_output';

    // Do not use the file_system service so this method can be called before
    // it is available. Checks !is_dir() twice around mkdir() because a
    // concurrent test might have made the directory and caused mkdir() to
    // fail. In this case we can still use the directory even though we failed
    // to make it.
    if (!is_dir($this->htmlOutputDirectory) && !@mkdir($this->htmlOutputDirectory, 0775, TRUE) && !is_dir($this->htmlOutputDirectory)) {
      throw new \RuntimeException(sprintf('Unable to create directory: %s', $this->htmlOutputDirectory));
    }
    if (!file_exists($this->htmlOutputDirectory . '/.htaccess')) {
      file_put_contents($this->htmlOutputDirectory . '/.htaccess', "<IfModule mod_expires.c>\nExpiresActive Off\n</IfModule>\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;
    }
  }
}