Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter"
provides a massive help when writing/debugging tests as you can see the page responses. However, in a scenario where you're using a temporary server (e.g. php -S localhost:8888
) rather than going through the full webserver, the output links aren't correct as it uses http://localhost:8888 as the base url for the links.
Proposed resolution
Allow use of an environmental variable to override the base url for those links.
Comment | File | Size | Author |
---|---|---|---|
#10 | 2996476-10-allow-alternative-browsertest-output-base-url.patch | 2.47 KB | andrewbelcher |
#2 | 2996476-2-allow-alternative-browsertest-output-base-url.patch | 1.54 KB | andrewbelcher |
Comments
Comment #2
andrewbelcher CreditAttribution: andrewbelcher at FreelyGive commentedHere's a patch.
Comment #3
dawehnerI'm wondering whether we should fix
$GLOBALS['base_url']
instead? Am I missing something?Comment #4
andrewbelcher CreditAttribution: andrewbelcher at FreelyGive commentedI'd assumed
$GLOBALS['base_url']
would be for the base URL that the test makes requests to (or at least would be expected to match that), which is why I made use of something separate.Comment #5
dawehnerI think I'm missing something. Why are these links incorrect?
Comment #6
andrewbelcher CreditAttribution: andrewbelcher at FreelyGive commentedIf you're using a remote server (e.g. a development box on digital ocean's cloud infra), to be able to view those files you need to use the servers URL, not localhost.
Comment #7
dawehnerGotcha, that makes sense. Do you mind documenting it in the phpunit.xml maybe?
Comment #8
jhedstromNeeds work to document this in
phpunit.xml.dist
as noted in #7.Comment #10
andrewbelcher CreditAttribution: andrewbelcher at FreelyGive commentedHere's an updated patch with the documentation.
Comment #12
jhedstromThis would also be useful in CI environments where tests might be run against
http://localhost
, but the site itself (where the output html would be accessed) would be at an externally accessible URL.I think the patch in #10 looks good and has addressed the above feedback.
Comment #13
alexpottCommitted and pushed a74c8c2b7d to 9.0.x and ba96ab0d0d to 8.9.x and d338a3d4e6 to 8.8.x. Thanks!
Backported to 8.8.x as a test only fix.