Closed (fixed)
Project:
Drupal core
Version:
9.1.x-dev
Component:
phpunit
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
27 Apr 2020 at 10:27 UTC
Updated:
11 Sep 2020 at 14:14 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
mondrakeStarted working on this.
Comment #3
longwavePerhaps we can even deprecate
drupalGetHeader()after this?Comment #4
mondrakeFirst iteration
Comment #5
mondrakeComment #6
mondrakeThis more or less should do, up for review now. I only replaced the occurences of
drupalGetHeaderwhere it's inlined in standard assertions. There remain a few cases wheredrupalGetHeaderis called and its value associated to a variable that is then used for further assertions or other cases. In general we can think of replacing all those with$this->getSession()->getResponseHeader($name);, and deprecatedrupalGetHeader, but I'd leave that to a follow-up since I think that deserves specific attention on how to convert.Comment #8
mondrakeFixing failure at #6
Comment #9
mondrakeComment #10
longwaveConversions here all look good. I agree with pushing the rest to a followup to keep this one simple.
Comment #11
jungleFor lines like this, is it necessary to introduce a variable for
$this->assertSession()? It gets called many times.Comment #12
jungleContinue with #11, if we are going to doing so, I think it should be done in a separate issue. As it does not just happen here.
Comment #13
mondrake#12 it's a good point. When we'll start removing legacy assertions following #3114617: Properly deprecate methods in Drupal\FunctionalTests\AssertLegacyTrait and Drupal\KernelTests\AssertLegacyTrait, while still keeping deprecations silenced, there will be tons of these.
But I think that will have to be addressed afterwards.
Also - now a WebAssert failure leads to an exception, and an Error (not a Failure) reported by PHPUnit. That's because in our implementation we do not catch Exceptions thrown by WebAssert. We may think about a new set of methods, included in a trait, used by FunctionalTests, that will absorb the Exception and report a Failure (with a context message, currently missing).
Kinda, instead of
$this->assertSession()->responseHeaderNotContains('Vary', 'cookie');rather
$this->assertSessionResponseHeaderNotContains('Vary', 'cookie', 'my bold failure message');Comment #14
longwaveLooked at the code behind this and I think we might be able to use this instead of assertNull?
Comment #15
longwaveNW for #14, apologies for not doing this before - set back to RTBC if you disagree!
Comment #16
mondrakeNo worries. I disagree, though: I was pondering about this the same way, but then IMHO what we want in cases like this is to check that the header is missing from the response, but in your suggestion it may exist but have a null value. What's missing I think is a
responseHeaderExistsmethod upstream in WebAssert.In Mink,
getResponseHeaderreturns null when the header is missing, so that's more accurate IMHO.Comment #17
longwaveAnd
responseHeaderEquals()checks that return value using===so $actual NULL will only check a NULL response and not pass for e.g. the empty string.Wouldn't
getResponseHeader()also return NULL if the header value was NULL instead of missing? Can a header value even be NULL, isn't it always a string or not set?Comment #18
mondrakeI guess you'd be right, still I think this would be confusing. I think it'd be better file a PR upstream to get a clear existence checking method. I see there's another similar pending https://github.com/minkphp/Mink/pull/630
Comment #19
mondrakeFiled #3132887: Deprecate BrowserTestBase::drupalGetHeader() for follow up.
Comment #20
xjmReviewing.
Comment #21
xjmWhy are we retaining
assertNull()here as the assertion? ... I see #14 - #18 are about this.Nice one.
This assertion (and the rest in this test) is adding debugging information about the type of the response (Response object, cacheable response object, render array as HTML, render array as AJAX, dialog, etc.). Since there's many similar assertions in the test, it is making debugging a little harder to go back to the exact line number, but it's manageable. In most cases in the test, the inline comments already include the needed information. However, there are a few where the information isn't included directly in the inline comments. I've highlighted those here. In most cases, these are giving additional information about the fixture being tested at that point.
Let's put this in the inline comments as well.
I got about halfway through the patch. In terms of scope management, I'm wondering if it might make sense to separate assertions that already don't have assertion messages from those that do?
Comment #22
xjmI think we should file a followup for #14 - #18 perhaps.
Comment #23
mondrakeon this
Comment #24
mondrakeI investigated #14-#18 and filed #3133355: Introduce PHPUnit-compliant WebAssert::responseHeaderExists() method, and its negative, we do not necessarily need to get upstream involved. Postponing on that.
Comment #25
mondrakeComment #26
mondrakeComment #27
mondrakeAdding Deprecated assertion tag. Related issue was committed, can be worked on now.
Comment #28
mondrakeOn this.
Comment #29
mondrakeJust a reroll for now.
Comment #30
mondrakeAdded calls to the new
WebAssert::responseHeaderDoesNotExistmethod to replace$this->assertNull($this->getSession()->getResponseHeader('X-Drupal-Cache'));calls, and inlined back the $message parameters as comments where appropriate.Comment #31
paulocsNice! Patch #30 looks good to me.
Set to RTBC.
May be we will need to re-roll patch from issue #3164589: Replace assertions that use $this->getSession()->getResponseHeader() with WebAssert methods after this issue is committed or the opposite. Both patches fixes the class BasicAuthTest.php. Let's see what will be committed first.
Cheers, Paulo.
Comment #32
mondrakeComment #33
longwaveRerolled.
Comment #34
longwaveOops, missed a change from responseHeaderEquals(..., NULL) to responseHeaderDoesNotExist()
Comment #35
mondrakethanks, back to rtbc
Comment #36
catchNot sure if there is a script issue, but the opening single quote from the assertion message is being reproduced in the code comment (first time I read it I was looking for the closing single quote).
This happens several times in the patch.
I'm also not sure the comment is correct as written - we're not asserting anything about a render array, only the cache headers. So I think we could remove these comments since the assertion is fairly self-documenting.
Comment #37
Vidushi Mehta commentedChanges are done mentioned by #36.
Comment #38
mondrakeThere's a line space error
But that may be fixable on commit.
Comment #39
mondrakeI think we can remove all of this too, then, based on #36.
Comment #40
Vidushi Mehta commented@mondrake I was also thinking the same but got confused so only removed the single quote comments mentioned in #36. Added a new patch and removed the line space error as well.
Comment #41
mondrakeThanks. Attached rawdiff between #34 and #40.
Comment #42
mondrakeComment #43
Vidushi Mehta commentedThanks for adding. I forgot to add the interdiff.
Comment #44
paulocsInterdiff between patch #37 and #40.
Also RTBC+1
Cheers, Paulo.
Comment #45
catch#40 looks great, but needs a re-roll for 9.1.x
Comment #46
Vidushi Mehta commentedComment #47
mondrakeSince we're at it, please remove also the CS issue from #40, see https://www.drupal.org/pift-ci-job/1803208
Comment #48
mondrakeRerolled
Comment #49
Vidushi Mehta commented@mondrake I've already created the patch and worked on so many file. Put efforts and time on that but now its not worth.
Comment #50
Vidushi Mehta commentedComment #51
mondrake@Vidushi Mehta oops sorry, I missed that. Apologies.
Comment #53
catchThe patch introduced a typo here, but still passed tests because the 403 response is also not cached. Out of scope to improve the test here, but we should open a follow-up to add an additional assertion to make sure the page we get back is valid.
Committed 3e0f015 and pushed to 9.1.x. Thanks!