Originally part of #2171683: Remove all Simpletest overrides and rely on native multi-site functionality instead:

The verbose output of headers in WebTestBase

  1. does not output HTTP request headers (which are sometimes needed for debugging)
  2. does output HTTP response headers, but they are dumped as a weird array.

Fixing this is especially useful for debugging Simpletest, but also for e.g. RESTTestBase.

This change is independent from the parent issue and was only included there, because I had to debug and find out why some test requests were not hitting the test site (which was ultimately caused by something else).

Comments

dawehner’s picture

Have we actually thought of using guzzle instead of raw CURL, just an off-topic question.

  1. +++ b/core/modules/rest/lib/Drupal/rest/Tests/RESTTestBase.php
    @@ -139,13 +139,15 @@ protected function httpRequest($url, $method, $body = NULL, $mime_type = NULL) {
    +      $verbose .= '<hr />Request headers: <pre>' . check_plain($this->requestHeaders[$i]) . '</pre>';
    +      $verbose .= '<hr />Response headers: <pre>' . check_plain($this->responseHeaders[$i]) . '</pre>';
    
    +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
    @@ -1333,7 +1363,10 @@ protected function drupalGet($path, array $options = array(), array $headers = a
    +        $verbose .= '<hr />Request headers: <pre>' . check_plain($this->requestHeaders[$i]) . '</pre>';
    +        $verbose .= '<hr />Response headers: <pre>' . check_plain($this->responseHeaders[$i]) . '</pre>';
    
    @@ -1523,7 +1556,10 @@ protected function drupalPostForm($path, $edit, $submit, array $options = array(
    +              $verbose .= '<hr />Request headers: <pre>' . check_plain($this->requestHeaders[$i]) . '</pre>';
    +              $verbose .= '<hr />Response headers: <pre>' . check_plain($this->responseHeaders[$i]) . '</pre>';
    
    @@ -1890,11 +1926,15 @@ protected function drupalHead($path, array $options = array(), array $headers =
    +      for ($i = 0; $i < $this->requestId; $i++) {
    +        $verbose .= '<hr />Request headers: <pre>' . check_plain($this->requestHeaders[$i]) . '</pre>';
    +        $verbose .= '<hr />Response headers: <pre>' . check_plain($this->responseHeaders[$i]) . '</pre>';
    +      }
    

    Any reason we don't use String::checkPlain? We could also move this + the for loop into a helper method.

  2. +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
    @@ -1230,9 +1258,11 @@ protected function curlHeaderCallback($curlHandler, $header) {
           $this->headers[] = array_pop($this->headers) . ' ' . trim($header);
    +      $this->responseHeaders[$this->requestId][] = array_pop($this->responseHeaders[$this->requestId]) . ' ' . trim($header);
    

    wonder whether it is sane to store trim($header);

sun’s picture

Thinking about this some more, I wondered:

Wouldn't it make sense to drop the WebTestBase::$dumpHeaders property and output these large chunks of request/response headers in (native) DETAILS instead?

► Request: GET /user/1
► Response: 200 OK
▼ Request: GET /node/2
...
...
► Response: 200 OK

→ Use a modern, standards-compliant browser (like Chrome) to get the proper, HTML5 standard details behavior.

If you do not, bad luck.

jibran’s picture

drupal8.test-headers.0.patch queued for re-testing.

sun’s picture

StatusFileSize
new9.78 KB
new45.37 KB

Now, how awesome is this:

Status: Needs review » Needs work

The last submitted patch, 4: drupal8.test-headers.4.patch, failed testing.

sun’s picture

Status: Needs work » Needs review
StatusFileSize
new9.74 KB

Oopsie ;)

jibran’s picture

  1. +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
    @@ -48,21 +48,25 @@
    +   * @var Array
    

    should be array.

  2. +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
    @@ -1217,12 +1222,20 @@ protected function curlExec($curl_options, $redirect = FALSE) {
    +    $this->requestHeaders[$this->requestId] = preg_split('/(.*\r\n)/m', curl_getinfo($this->curlHandle, CURLINFO_HEADER_OUT), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
    

    please add comment here to explain it.

  3. +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
    @@ -3621,6 +3626,47 @@ protected function assertMailPattern($field_name, $regex, $message = '', $group
    +    $verbose = '<meta charset="utf8" />';
    +    $verbose .= $method . ' ' . String::checkPlain($uri) . ' ? ' . String::checkPlain($this->getUrl());
    ...
    +      $verbose .= '<details style="margin: 0;">';
    +      $verbose .= '<summary>' . String::checkPlain($request_status_header) . '</summary>';
    +      $verbose .= '<pre>' . String::checkPlain(implode('', $this->requestHeaders[$i])) . '</pre>';
    +      $verbose .= '</details>';
    ...
    +      $verbose .= '<details style="margin: 0;">';
    +      $verbose .= '<summary>' . String::checkPlain($response_status_header) . '</summary>';
    +      $verbose .= '<pre>' . String::checkPlain(implode('', $this->responseHeaders[$i])) . '</pre>';
    +      $verbose .= '</details>';
    ...
    +    $verbose .= '<hr />';
    +    $verbose .= $response_body;
    

    Please us heredoc.

sun’s picture

StatusFileSize
new9.94 KB

1+2 done.

Not going to do 3, because it does not improve the markup generation in any way (and only adds more complexity to this verbose output code).

sun’s picture

#2182315: simpletest verbose output doesn't show end result of a drupalPostAjaxForm() added verbose output to drupalPostAjax() just a few hours before I rolled the last patch, which does not appear to be covered here yet.

sun’s picture

Status: Needs work » Needs review
StatusFileSize
new11.63 KB
new5.39 KB
  1. Fixed verbose header output.
  2. Fixed bogus assertion line for POST requests that redirect to a new location.
jhedstrom’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
rpayanm’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new11.49 KB

Status: Needs review » Needs work

The last submitted patch, 13: 2176043-13.patch, failed testing.

Status: Needs work » Needs review

rpayanm queued 13: 2176043-13.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 13: 2176043-13.patch, failed testing.

mgifford’s picture

Assigned: sun » Unassigned

Unassigning so someone else can take it on.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

Project: Drupal core » SimpleTest
Version: 8.9.x-dev » 8.x-3.x-dev
Component: simpletest.module » Code
Issue tags: +Bug Smash Initiative

Triaging issues in simpletest.module as part of the Bug Smash Initiative to determine if they should be in the Simpletest Project or core.

This looks like it belongs in the Simpletest project.