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
BrowserTestBase currently only does verbose HTML output logging for a requested page if the methods drupalGet() and similar are used, which have explicit logging. We want the logging at all times, even if developers use the native mink methods directly to click a link for example.
Proposed resolution
Add a Guzzle middleware for browser tests that always performs logging. Remove the explicit logging from drupalGet() and friends since it will be done for all requests anyway.
Remaining tasks
Patch.
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#37 | mink-log-2763401-37-8.2.x.patch | 2.69 KB | jofitz |
#37 | mink-log-2763401-37-8.3.x.patch | 2.66 KB | jofitz |
#22 | mink-log-2763401-22.patch | 6.43 KB | Sam152 |
#22 | interdiff.txt | 3 KB | Sam152 |
#11 | mink-log-2763401-11.patch | 6.42 KB | klausi |
Comments
Comment #2
klausiThis is what I have in mind.
Advantages: catch all middleware, no request is lost. Very little code for us to maintain.
Disadvantage: only works with GoutteDriver, so it does not work for JavascriptTestBase.
This will also print redirect responses to the debug output. When you view the redirect responses in your browser then the http-equiv="refresh" meta tag is invoked and the browser redirects away. We should avoid this somehow.
Comment #3
klausiIf only Mink had the concept of middlewares on the driver level same as Guzzle has :-(
The alternative to this is using the proxy pattern and implement a transparent DrupalTestDriver for Mink which wraps the actual driver class. And then implement request logging on many methods of DriverInterface.
Comment #4
klausiWe should also print the calling test class method and line number to help people find the offending line in their test.
Comment #5
klausiAnd here is the fix to remove the refresh meta tag to avoid browser redirects when looking at the HTML file.
The middleware is now getting a bit long and should be moved to a dedicated method in BTB in the next iteration of this.
Comment #6
klausiHere is a patch that experiments with a decorator/proxy for Mink drivers. The problem is that the drivers also perform requests internally which are not routed through the public function of DriverInterface. Example: a click() call can mean that a form is submitted with the push of a button, but the call does not go through submitForm() of the driver, so we cannot log it.
So I think that approach is not feasible for us and we will have to stick to a Guzzle middleware for BrowserTestBase. Pus explicit logging in JavascriptTestBase for now until we can come up with a better idea.
Comment #7
klausiContinuing with the Guzzle middleware approach, moving it to a dedicated method.
Restored the explicit logging in drupalGet() and submitForm() to keep logging when using JavascriptTestBase with the PhantomJS driver.
Comment #9
dawehnerIn general this looks really nice!
nitpick: typo in callablke
Just a suggestion: I would just mention JavascriptTestBase for convencience
we could do a formatHtmlOutputHeaders
Comment #10
dawehnerComment #11
klausiRerolled and addressed your comments. Thanks!
Comment #12
dawehnerThank you for addressing the feedback!
Comment #13
benjy CreditAttribution: benjy at PreviousNext commentedLooks good to me, just one small improvement, for less lines of code :)
This could just be return
return implode(';', array_map('trim', (array) $header));
Comment #15
klausiSeems like a random test fail, green again.
Comment #17
klausiTest is green, back to RTBC.
Comment #18
alexpottNeat fix. Committed 761657a and pushed to 8.3.x. Thanks!
Setting to patch to be ported for eventual cherry-pick to 8.2.x once 8.2.0 is released.
Comment #20
alexpottIf we want this in 8.2.x then we need to prefix these methods with an underscore. Alternatively if we are happy to have this fix in 8.3.x only we can just mark it as fixed.
Comment #21
dawehnerGiven that we do most of the conversions hopefully in 8.3.x the win is probably not that high. On the other hand we want to make things easier for contrib and custom modules.
Comment #22
Sam152 CreditAttribution: Sam152 at PreviousNext commentedI'd like to see this in 8.2.x. I have client projects with test suites that could benefit from this.
I haven't seen internal class methods prefixed with an underscore or where this is documented? You'd think that's what private was for? In any case if that's the approach, patch attached.
Comment #24
Sam152 CreditAttribution: Sam152 at PreviousNext commentedComment #25
Sam152 CreditAttribution: Sam152 at PreviousNext commentedComment #27
Sam152 CreditAttribution: Sam152 at PreviousNext commentedThis passes against 8.2.x. Back to review.
Comment #28
dawehnerThis looks alright for me
Comment #29
klausi@alexpott: Why do we prefix those methods with an underscore? Then they are different in 8.3.x and 8.2.x and cause headaches for people working with them in both branches?
Comment #30
dawehnerThis is our BC policy, see https://www.drupal.org/core/d8-bc-policy and
Underscore-prefixed functions and methods
Comment #31
xjmWhen @catch and @alexpott raised this issue this morning, my thought was that the underscore prefixes were only a workaround to allow us to backport fixes for (e.g.) major bugs when we could not do so otherwise. I don't think it was ever intended as a way to backport API additions to patch releases. But worth discussing the case of this issue in #2773087: [policy, maybe patch] Clarify backport policy for testing framework changes, including new BTB tests.
For me #22 alone as a reason to do this violates semver in principle, and there is a risk of disruption from it because BTB is intended as an extension point. On the other hand, I think we all consider BTB experimental in our heads, which means it's a pre-release version that we can add API to. But adding protected methods to a base class that is intended to be directly subclassed does risk breaking people's BTB tests.
Let's discuss more on #2773087: [policy, maybe patch] Clarify backport policy for testing framework changes, including new BTB tests?
Comment #32
jhedstromI haven't pinned down the exact cause yet, but this logic can lead to
Undefined offset: 1
errors, but only on certain GET requests.Comment #33
jhedstromI added #2822387: Undefined offset 1 in BrowserTestBase::getMethodCaller() for the issue mentioned in #32.
Comment #34
Wim LeersConfirming what @jhedstrom wrote in #32. This is exactly what I'm seeing in #2737719-134: EntityResource: Provide comprehensive test coverage: for every entity type, every format, every method and #2737719-137: EntityResource: Provide comprehensive test coverage: for every entity type, every format, every method's patches against 8.3.x.
Postponing this on #2822387: Undefined offset 1 in BrowserTestBase::getMethodCaller(), so that the same bug is not introduced in 8.2.x.
Comment #35
Wim LeersComment #36
Wim Leers#2822387: Undefined offset 1 in BrowserTestBase::getMethodCaller() landed. This can now continue for 8.2.x. But it'll need a reroll, to incorporate the fixes from #2822387: Undefined offset 1 in BrowserTestBase::getMethodCaller().
Comment #37
jofitz CreditAttribution: jofitz at ComputerMinds commentedComment #41
jofitz CreditAttribution: jofitz at ComputerMinds commentedRemove "Needs reroll" tag.
Comment #42
dawehnerWe probably won't get this into 8.2.x, so we on the other hand don't need underscores then.
Comment #44
klausiOK, so let's call this fixed in 8.3.x without 8.2.x backport.