Commit ac5428e8 authored by xjm's avatar xjm

Issue #2809117 by klausi, dawehner, marcoscano, Mile23, xjm, fgm, jhodgdon:...

Issue #2809117 by klausi, dawehner, marcoscano, Mile23, xjm, fgm, jhodgdon: Integrate PHPUnit verbose output in Simpletest UI
parent ee23c187
...@@ -317,6 +317,7 @@ function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpun ...@@ -317,6 +317,7 @@ function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpun
// this variable. // this variable.
if ($base_url) { if ($base_url) {
putenv('SIMPLETEST_BASE_URL=' . $base_url); putenv('SIMPLETEST_BASE_URL=' . $base_url);
putenv('BROWSERTEST_OUTPUT_DIRECTORY=' . \Drupal::service('file_system')->realpath('public://simpletest'));
} }
$phpunit_bin = simpletest_phpunit_command(); $phpunit_bin = simpletest_phpunit_command();
...@@ -324,6 +325,8 @@ function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpun ...@@ -324,6 +325,8 @@ function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpun
$phpunit_bin, $phpunit_bin,
'--log-junit', '--log-junit',
escapeshellarg($phpunit_file), escapeshellarg($phpunit_file),
'--printer',
'\\\Drupal\\\Tests\\\Listeners\\\SimpletestUiPrinter',
); );
// Optimized for running a single test. // Optimized for running a single test.
...@@ -357,6 +360,7 @@ function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpun ...@@ -357,6 +360,7 @@ function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpun
putenv('SIMPLETEST_DB='); putenv('SIMPLETEST_DB=');
if ($base_url) { if ($base_url) {
putenv('SIMPLETEST_BASE_URL='); putenv('SIMPLETEST_BASE_URL=');
putenv('BROWSERTEST_OUTPUT_DIRECTORY=');
} }
return $ret; return $ret;
} }
......
<?php
namespace Drupal\simpletest\Tests;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\simpletest\Functional\SimpletestPhpunitBrowserTest;
/**
* Test PHPUnit output for the Simpletest UI.
*
* @group simpletest
*
* @see \Drupal\Tests\Listeners\SimpletestUiPrinter
*/
class UiPhpUnitOutputTest extends WebTestBase {
/**
* Modules to enable.
*
* @var string[]
*/
public static $modules = ['simpletest'];
/**
* Tests that PHPUnit output in the Simpletest UI looks good.
*/
public function testOutput() {
require_once __DIR__ . '/../../tests/fixtures/simpletest_phpunit_browsertest.php';
$phpunit_junit_file = $this->container->get('file_system')->realpath('public://phpunit_junit.xml');
// Prepare the default browser test output directory in the child site.
$this->container->get('file_system')->mkdir('public://simpletest');
$status = 0;
$output = [];
simpletest_phpunit_run_command([SimpletestPhpunitBrowserTest::class], $phpunit_junit_file, $status, $output);
// Check that there are <br> tags for the HTML output by
// SimpletestUiPrinter.
$this->assertEqual($output[18], 'HTML output was generated<br />');
// Check that URLs are printed as HTML links.
$this->assertIdentical(strpos($output[19], '<a href="http'), 0);
}
}
<?php
namespace Drupal\Tests\simpletest\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* A PHPUnit-based browser test that will be run from Simpletest.
*
* To avoid accidentally running it is not in a normal PSR-4 directory.
*
* @group simpletest
*/
class SimpletestPhpunitBrowserTest extends BrowserTestBase {
/**
* Dummy test that logs the visited front page for HTML output.
*/
public function testOutput() {
$this->drupalGet('<front>');
$this->assertSession()->responseContains('<h2>TEST escaping</h2>');
}
}
<?php
namespace Drupal\Tests\Listeners;
use Drupal\Component\Utility\Html;
/**
* Defines a class for providing html output links in the Simpletest UI.
*/
class SimpletestUiPrinter extends HtmlOutputPrinter {
/**
* {@inheritdoc}
*/
public function write($buffer) {
$buffer = Html::escape($buffer);
// Turn HTML output URLs into clickable link <a> tags.
$url_pattern = '@https?://[^\s]+@';
$buffer = preg_replace($url_pattern, '<a href="$0" target="_blank" title="$0">$0</a>', $buffer);
// Make the output readable in HTML by breaking up lines properly.
$buffer = nl2br($buffer);
print $buffer;
}
}
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