See #2735005: Convert all Simpletest web tests to BrowserTestBase (or UnitTestBase/KernelTestBase)
Converting these tests revealed a bug in BrowserTestBase where certain redirects where not followed. The reason this is a problem: \Symfony\Component\HttpFoundation\RedirectResponse uses the lower-case variant of meta[http-equiv="refresh"]… which means any Symfony redirect response will not be followed correctly by the current check for meta[http-equiv="Refresh"]
See #2905818: Make sure \Drupal\Tests\BrowserTestBase::checkForMetaRefresh is case insensitive
| Comment | File | Size | Author |
|---|---|---|---|
| #39 | 2863607-39.patch | 14.69 KB | lendude |
| #39 | interdiff-2863607-28-39.txt | 638 bytes | lendude |
| #29 | 2863607-28.patch | 15.45 KB | wim leers |
| #25 | 2863607-25.patch | 14.24 KB | lendude |
| #25 | interdiff-2863607-22-25.txt | 2.62 KB | lendude |
Comments
Comment #2
jofitzKicked-off the conversion by:
(and corrected the component on the issue)
Comment #4
dawehnerI think you can replace
inside
BigPipeTestwith$this->getSession()->reset().Comment #5
wim leersI had started doing this weeks/months ago. It's mighty difficult.
Comment #6
wim leersComment #7
michielnugter commentedComment #8
lendudeThis needs #2862885: Batch: Convert system functional tests to phpunit because of checkForMetaRefresh() use in
BigPipeTestComment #9
naveenvalechaThis issue landed #2862885: Batch: Convert system functional tests to phpunit and it unblocked this one. However, this still needs to replace the curlOpen(); and curlClose();
Will link if I will find any follow-up issue for the same otherwise will open a new one.
//Naveen
Comment #11
naveenvalechaHere we go with another hit.
Comment #13
naveenvalechaOnly this file core/modules/big_pipe/src/Tests/BigPipeTest.php is left for conversion. So this is the TODO left.
//Naveen
Comment #15
naveenvalechaComment #16
naveenvalechaComment #19
lendudeManaged to get some methods to come back green.
\Drupal\big_pipe\Tests\BigPipePlaceholderTestCaseswasn't happy when moved, and didn't feel like finding out why.\Drupal\Tests\big_pipe\Functional\BigPipeTest::assertBigPipeNoJsMetaRefreshRedirectneeded a extensive rewrite since there where more redirects that needed to be blocked and since getResponseHeaders returns something completely different in BrowserTestBase then WebTestBase.Interdiff is against #2 since that seemed like a good path forward, I don't think
\Drupal\Tests\big_pipe\Functional\BigPipeTestshould be out of scope.Comment #21
lendudejust this?
Comment #22
lendudeMoved
BigPipePlaceholderTestCasesto a discoverable place. This cleans out the /core/modules/big_pipe/src/Tests dir.Comment #23
lendudeNot happy with this. I couldn't find a way to make the redirect go one step at a time. Once I blocked it, it didn't matter what URL I called, it never seemed to redirect.
Comment #24
wim leersFirst off: thank you so much for pushing this forward! I'm so tempted to mark this RTBC, but I have a few small remarks, and a few bigger ones. This is one of the trickiest tests in Drupal core, because it's what gives us all strong assurances (and hence peace of mind) that BigPipe is actually working correctly. So I am reviewing in the strictest possible way. The fact that I can find so few things to remark upon, says a lot — great job! 👏
I strongly disagree with this move, because it's also used by
BigPipeTest.Why these changes?
Yay!
This is the magic thing I hadn't found yet in my attempt I mentioned in #5.
This was overriding
WebTestBase::$maximumMetaRefreshCount— so this can now be deleted.Same for this.
This is 100x more elegant!
Wonderfully elegant updates here!
The changes here are confusing. Removing the newly added comment would make it easier to understand.
Then the other thing that's noteworthy is that the "Two requests were made upon following…" assertion was removed. Why?
Why do we need to perform this request separately?
That means
performMetaRefresh()is no longer working in the same way as it was before. Which also means we're not longer actually able to test that the redirect actually works correctly, since we're doing something manually here that wasn't being done manually before.Comment #25
lendude@Wim Leers thanks so much for the review! And strict reviews are welcome.
#24.1 My goal was to clear out the /core/modules/big_pipe/src/Tests dir, hence the move. But it needed to be in a spot where it could be discovered and this worked (/core/modules/big_pipe/tests/src didn't), really wasn't any additional logic to that, so if you can think of a better place (or just want to leave it where it was), I'm fine with that.
#24.2 Because that made the test pass :) Seems like NodeElement->getText() strips some white space that SimpleXML (string) casts leave in.
#24.3 :)
#24.4 :)
#24.5 That is also a thing in BrowserTestBase, so that's still needed I think
#24.6 That is also a thing in BrowserTestBase, so that's still needed I think
#24.7 :)
#24.8 :)
#24.9 Took the comment out, that was left over from earlier attempt I made at making it pass. And the test was taken out because there doesn't seem to be way to check this in BrowserTestBase. WebTestBase returned all the headers for all the request, and that could be used to determine the number of redirects that were done. Made an attempt at that in this version of the patch.
#24.10 Wasn't happy with that (see my comment in #23). But it seems that once the cookie is set, there is no way to continue the request and follow all the redirects to the end. So new attempt to simulate this: Do the first step of the redirect, check stuff, unset the cookie, go to the original URL and don't block the redirects, and see if at the end of it we end up in the right spot with the right cookie.
Comment #26
wim leers\Drupal\simpletest\TestDiscovery::scanDirectory()or something related.Fixing that is out of scope here. I tried both
Drupal\Tests\big_pipe\BigPipePlaceholderTestCasesandDrupal\Tests\big_pipe\Unit\BigPipePlaceholderTestCasesand could not get it to work. Very strange. So… then your solution definitely seems the next best alternative! 👍checkForMetaRefresh()didn't exist yet. So that is why many of the problems I was having are no longer there, yay! :) (I was re-implementing that myself.) Great, then the patch is fine as-is :)The only other thing I found was a few comments with now outdated FQCN references: nitpicks. Fixed those already.
Comment #27
wim leersTo be clear: points 9+10, the
performMetaRefresh()changes is the only thing I'm concerned about, the rest looks RTBC-worthy already! :)Comment #28
jibranWhy do we still have this line?
Comment #29
wim leersI found the root cause for the chaos!
\Drupal\simpletest\WebTestBase::checkForMetaRefresh()does$refresh = $this->xpath('//meta[@http-equiv="Refresh"]');, which matches both<meta http-equiv="Refresh"…and<meta http-equiv="refresh"…\Drupal\Tests\BrowserTestBase::checkForMetaRefresh()does$refresh = $this->cssSelect('meta[http-equiv="Refresh"], which matches<meta http-equiv="Refresh"…but NOT<meta http-equiv="refresh"….The solution is to change the latter to
(This is a regression caused by #2862885: Batch: Convert system functional tests to phpunit.)
The reason this is a problem:
\Symfony\Component\HttpFoundation\RedirectResponseuses the lower-case variant… which means any Symfony redirect response will not be followed correctly.With that bug out of the way, the solution becomes much simpler. We can simply not change anything about
\Drupal\Tests\big_pipe\Functional\BigPipeTest::performMetaRefresh(), and the change toassertBigPipeNoJsMetaRefreshRedirect()becomes much simpler: fromto
… which IMHO is very easy to understand :)
Comment #30
wim leersIf you agree with #29, Lendude, feel free to RTBC!
Comment #31
lendude@Wim Leers yes this makes it sooooo much cleaner! I tried the double
$this->performMetaRefresh();and couldn't get it to work, great find.With this fix, bumping this to a bug, test coverage is a little indirect, but does the trick I feel.
Updated the IS to include the fix.
Comment #32
wim leers/me high-fives Lendude 🖐
Great teamwork!
P.S.: just realized this isn't a bug, but a task :)
Comment #33
larowlanSorry to do this, but I think this is scope creep. We should open a separate issue for this, and postpone this one on it.
Our guidelines are pretty clear in this regard https://www.drupal.org/core/scope
Comment #34
larowlanAlso, the title of the issue was the red-flag for scope creep
Convert WebTestBaseTests of BigPipe to BrowserTestBase and make the redirect following in BrowserTestBase work for lower case refresh
:-)
Comment #35
wim leersUgh … really? :(
Clearly it was case-insensitive in
WebTestBase. We're converting one more test fromWebTestBasetoBrowserTestBase. In doing so, we found something inBrowserTestBasethat was not forgiving enough, so we're fixing it.Doesn't that make perfect sense? Do we really want explicit test coverage for this in
BrowserTestBaseTest?If you still think that's what we want, I'll do it, but I personally think it's overkill.
Comment #36
yoroy commentedAs far as I can tell: yeah, really :)
Comment #37
larowlanYes please create a new issue, and ping me with it, we'll get it in quick
Comment #38
lendudeHere is the split issue #2905818: Make sure \Drupal\Tests\BrowserTestBase::checkForMetaRefresh is case insensitive
Comment #39
lendudeThis is the patch without the change to BrowserTestBase, should be green once #2905818: Make sure \Drupal\Tests\BrowserTestBase::checkForMetaRefresh is case insensitive lands.
Comment #40
wim leersPostponing this on #2905818: Make sure \Drupal\Tests\BrowserTestBase::checkForMetaRefresh is case insensitive. #39 should fail until that's committed.
Comment #41
larowlanBlocker is in - thanks
Comment #42
larowlanRetested
Comment #43
wim leers@larowlan is operating at lightning speed! 🏎
Comment #44
wim leersAnd green again, so back to RTBC :)
Comment #45
larowlanI think we can just remove these
Containsnow? Not there for a particular reason?Can be fixed on commit.
Comment #46
wim leers#45: Correct — that class is just being moved, so we didn't do that to minimize changes. But you're right, it can be removed per new coding standards.
Is indeed safe to fix on commit :)
Comment #49
larowlanCommitted as 8b52ba0 and pushed to 8.5.x.
Cherry-picked as 2e02c13 and pushed to 8.4.x.
Comment #50
wim leersThanks!
Comment #51
larowlanFixing version given backport