Closed (fixed)
Project:
Drupal core
Version:
8.4.x-dev
Component:
block_content.module
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
19 Jun 2017 at 12:21 UTC
Updated:
5 Nov 2017 at 21:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
naveenvalechaComment #4
naveenvalechaBlocker has landed
Comment #5
naveenvalechaUpdated title
Comment #6
naveenvalechaHere's the start with failing tests
Comment #7
naveenvalechaComment #8
naveenvalechaThis would be green.
I'm to make this change because assertNoRaw is also getting the body tag in the html and it was able to find the body tag. So I replaced it with the cssSelect. Is this #2335057: Undefined method getUrl in AssertContentTrait::parse causes fatal error similar?
Comment #10
lendudeThis is much better, much more specific in what we are testing, I would however use assertEmpty() because assertFalse would expect a boolean.
I would also update the positive assertion to match, so we know that we are not breaking coverage here (negative assertions tell us very little):
to something like
$this->assertNotEmpty($this->cssSelect('tr#block-body'), 'Body field was found.');Since we are only converting one test here I think we can be lenient in our normal 'keep changes to a minimal'-policy. This patch will still be reviewable with some additional changes.
Comment #11
Anonymous (not verified) commented#10: nice catch about positive assertion! We really lost this assertion if converting as-is. Also i not found other cases in this test where the
'string'matches with html tag inside assertRaw/assertNoRaw methods.Replace
assertFalse/assertNotEmptyalso makes sense. I double check thefindAll(), and this method always returns array (except case where it returns result fromfind(), because this method can throws exceptions, but assert reacts to them correctly).Hah, one fun moment, page has not tag with
'#block-body'. So:$this->assertFalse($this->cssSelect('tr#block-body'), 'Body field was not found.');works like
$this->assertRaw('Body', 'Body field was found.');Let's fix this selector. Example with '#edit-body-0-value'.
Comment #12
phenaproximaThis looks pretty good to me.
Being a web test, couldn't this be
$this->assertSession()->elementExists('css', '#edit-body-0-value')? I assume there was a good reason for using $this->cssSelect() (although I've never used it), so I defer to the expertise of everyone else on that point.Comment #15
xjmAt first I was like "Huh it's not changing what it extends?" but of course that's because we left the old, deprecated base classes in place, so changing the namespace is sufficient to change which
BlockContentTestBaseit uses.Having both assertions can leave us reasonably sure that we don't need to worry about false positives/negatives, so that works for me. Thanks @Lendude for suggesting what a fix for what would have raised a red flag for me otherwise. :)
For #12, I think they're equivalent, no? So either seems fine. At least, I don't know of a particular reason to prefer one or the other, so I committed it as-is. We can file a followup if we want to change it further, I think.
Committed and pushed to 8.5.x and cherry-picked to 8.4.x. Thanks!