Problem/Motivation
HttpKernelUiHelperTrait::getUrl() returns something that looks like:
but if you pass that to drupalGet(), it prepends a / to it and you get a broken URL.
Steps to reproduce
Proposed resolution
Not sure. We already added a special case for query links to drupalGet() (#3589626: clickLink in kernel tests erroneously prefixes some paths with /), and adding ANOTHER special case is starting to get complicated.
I have a hunch that maybef the special handling I'd added to the browser at the symfony level was needed after all.
We could make getUrl() return a url without a domain, e.g.:
/node/2
but would that break other things?
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3594522
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
joachim commented> I have a hunch that maybef the special handling I'd added to the browser at the symfony level was needed after all.
The bit I mean is commit 40f2cc07edabd8cf86f67deb8cb25274a4ddb7af in branch 3390193-add-drupalget-with-mink-to-kerneltestbase in the fork for #3390193: Add a drupalGet() method to KernelTestBase.
This added a custom browser class whose job was to convert all URLs to relative:
I don't remember the details, but what I **think** this meant was that we let Mink handle converting any URL we passed into its browser, and then at the end we make it into something that the HTTP kernel can work with.
I'm wondering whether with this, we fix this bug and also we no longer need the special handling for anchor links.
Comment #3
joachim commentedYes, restoring that makes this work:
Comment #4
joachim commentedHmm but it doesn't work with relative query links.
And HttpKernelBrowser::getAbsoluteUri() is doing weird stuff to the URLs in that scenario (#3589626: clickLink in kernel tests erroneously prefixes some paths with / didn't add a test for it)
Comment #5
joachim commentedComment #7
joachim commentedMaking a draft MR with some of my work so far.
Overriding getAbsoluteUri() fixes one thing, but breaks another!!!
I've also tried stripping the host from the URL using the PHP 8.5 Uri\Rfc3986\Uri class like this:
but in some calls, the call to parent::getAbsoluteUri() is doing WEIRD STUFF to a relative URL.
Comment #8
joachim commentedActually, if we're doing to use Uri\Rfc3986\Uri, then maybe we should use it to manipulate getUrl() to return a path (eg. '/my/page'), that way the manipulation is targeted only where it needs to be done, instead of on every drupalGet() call.
Comment #9
joachim commentedThat works!
Comment #10
mstrelan commentedI haven't looked at the MR here but my gut feel is that passing
Urlobjects is generally better than passing strings.Comment #11
joachim commentedTrue, but then we'd be diverging totally from the getUrl() in browser tests.
Comment #12
mstrelan commentedWhat about introducing
getUrlObjectandgetUrlString(bool $absolute)for both kernel and functional, and deprecatinggetUrl? Then conversions that callgetUrlcan switch togetUrlObject. This would be similar to the approach of deprecatingxpath()in favour of more explicit functions.Comment #13
joachim commentedOk with getUrlObject().
But getUrlString() on kernel tests has no purpose as an absolute URL
Comment #14
joachim commentedAlso, what kind of Url object? Drupal URL or PSR URL?
Comment #15
mstrelan commentedWhichever one you can pass to drupalGet(), I think durpal