Commit 9d5b5a53 authored by catch's avatar catch

Issue #2469721 by larowlan, alexpott, dawehner, jibran: Add functionality to...

Issue #2469721 by larowlan, alexpott, dawehner, jibran: Add functionality to store browser output to BrowserTestBase
parent dd8056fb
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
namespace Drupal\Tests\simpletest\Functional; namespace Drupal\Tests\simpletest\Functional;
use Drupal\simpletest\BrowserTestBase; use Drupal\Tests\BrowserTestBase;
/** /**
* Tests BrowserTestBase functionality. * Tests BrowserTestBase functionality.
......
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true" beStrictAboutOutputDuringTests="true"
beStrictAboutChangesToGlobalState="true" beStrictAboutChangesToGlobalState="true"
checkForUnintentionallyCoveredCode="false"> checkForUnintentionallyCoveredCode="false"
printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter">
<php> <php>
<!-- Set error reporting to E_ALL. --> <!-- Set error reporting to E_ALL. -->
<ini name="error_reporting" value="32767"/> <ini name="error_reporting" value="32767"/>
...@@ -15,6 +16,8 @@ ...@@ -15,6 +16,8 @@
<!-- Example SIMPLETEST_BASE_URL value: http://localhost --> <!-- Example SIMPLETEST_BASE_URL value: http://localhost -->
<env name="SIMPLETEST_DB" value=""/> <env name="SIMPLETEST_DB" value=""/>
<!-- Example SIMPLETEST_DB value: mysql://username:password@localhost/databasename#table_prefix --> <!-- Example SIMPLETEST_DB value: mysql://username:password@localhost/databasename#table_prefix -->
<env name="BROWSERTEST_OUTPUT_DIRECTORY" value=""/>
<!-- Example BROWSERTEST_OUTPUT_DIRECTORY value: /path/to/webroot/sites/simpletest/browser_output -->
</php> </php>
<testsuites> <testsuites>
<testsuite name="unit"> <testsuite name="unit">
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
namespace Drupal\FunctionalJavascriptTests; namespace Drupal\FunctionalJavascriptTests;
use Drupal\simpletest\BrowserTestBase; use Drupal\Tests\BrowserTestBase;
use Symfony\Component\CssSelector\CssSelector; use Symfony\Component\CssSelector\CssSelector;
use Zumba\Mink\Driver\PhantomJSDriver; use Zumba\Mink\Driver\PhantomJSDriver;
......
This diff is collapsed.
<?php
namespace Drupal\Tests\Listeners;
/**
* 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;
/**
* {@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');
}
}
/**
* {@inheritdoc}
*/
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);
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment