Closed (fixed)
Project:
Drupal core
Version:
9.4.x-dev
Component:
taxonomy.module
Priority:
Major
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
8 Nov 2021 at 17:45 UTC
Updated:
29 Apr 2022 at 11:59 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
danflanagan8One of these tests (TermTranslationTest) uses the
AssertBreadcrumbTraitwhich itself relies on classy and is being handled in a separate issue: #3248309: AssertBreadcrumbTrait should not rely on Classy.So this patch is going to fail that test, but everything else should be good. We can run the tests again when the blocking issue is resolved.
Comment #3
danflanagan8Postponing this until #3248309: AssertBreadcrumbTrait should not rely on Classy is committed.
Comment #4
danflanagan8The blocking issue was just committed so I'm going to un-postpone and trigger the tests.
Comment #5
danflanagan8The patch passes now, as expected.
Comment #6
danflanagan8Comment #7
mglamanGoing to go bold and to mark RTBC. It's just selector changes. Looks clean to me. Left some notes to help anyways else reviewing.
I was weary about this at first, but realized the test installs Views
This feels fragile, but I can't imagine there is a better way.
nth-of-type docs for anyone who needs them https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-of-type
Seems the most reasonable way to target a specific sibling div.
Comment #8
xjmNice work on this!
I spent a good bit of time reviewing the last two tests closely and have some suggestions for making them less fragile.
So this is somewhat safe, because the test has both positive and negative assertions with the same xpath with different numbers of results.
However, I think these assertion groups would be more robust if we were actually asserting that the nodes' labels are or aren't present as we expected in every case, so that it's not only dependent on the markup structure. This is especially important for the last assertion, which could easily lead to a false positive with a markup change. The trick to testing against markup is always to have both positive and negative assertions about the thing, and to test both the markup and the text related to it.
For this test, I don't think we're entirely testing the right things.
Thanks!
Comment #9
danflanagan8Thanks @xjm!
Very nicely said.
I was approaching these classy-to-stark issues as if we were just doing the least possible work to make the test work with stark in the same way it works with classy, even if the current tests weren't perfect. Essentially changing xpath/css selectors. That's a pretty narrow scope.
Your comments imply that you think the scope is or should be larger. That we should make tests more robust where possible (8.1) or even substantively change the tests that may be missing coverage (8.2). Where should the line be drawn for this and the "sibling" issues?
Comment #10
xjm@danflanagan8, for issues like this where there's a lot of reliance on specific markup, I think adding more assertions (especially positive/negative pairs or text/xpath pairs) to ensure the test is sufficiently robust regardless of theme is in scope, because we're changing the default assumptions of the test.
However, when we have a potential "problem test" like these last two, it's also completely reasonable to split those off into separate issues. So one patch can contain all the tests where decoupling is straightforward, and followup issues can be added for tests that require additional assertions for forward-compatibility.
Thanks!
Comment #11
danflanagan8Thanks @xjm!
That sounds like a reasonable approach to me. Kind of a case-by-case basis. In this case, let's move forward with updating the patch to incorporate your feedback from #8.
Comment #12
danflanagan8Here's a patch with the updates requested in #8.
I also did a _little_ extra for
TermDisplayConfigurableTestin that there are assertions specifically about whether or not something is linked to the term. It seemed like that assertion might as well be there since it's something that changes over the course of the test.Comment #13
dwwBefore
After
Review
Can/should this now use
Drupal\Tests\system\Functional\Menu\AssertBreadcrumbTrait, instead?And here?
I know we just did the
elementsCount(), but would it be useful to add an explicit one of these here, too:?
This definitely addresses @xjm's concern in #8.1.
However, for the positive text assertions, would it not be better to assert the label is inside the link we just found? E.g. something more like this?
This pattern repeats many times in the patch. If this (or something like it) is better, let's fix them everywhere.
All the
pageTextNotContains()in the patch are good as-is. I'm only talking about the newpageTextContains()references to be refactored to check the actual link text, not the whole page response.Although, any reference to
pageTextNotContains()could be a candidate for anotherlinkByHrefNotExists().Nit: "... should be the second field..."
Wonder if these would be more readable as
xpath. E.g. I find[2]in the right spot in an xpath generally more readable than:nth-of-type(2). Mostly a personal preference thing. Not worth changing just for this, but flagging it in case others agree.I'm not going to NW for any of this, but not RTBC'ing, either. Curious to hear what others think of these points.
Thanks so much, @danflanagan8!
Comment #14
danflanagan8I'm not waiting for anyone else to chime in because I think those are all excellent suggestions, @dww. I believe this patch handles everything.
For 13.4 I went with a pattern like this:
That xpath goes straight for the jugular!
While refactoring the breadcrumb assertions, I didn't really know what to do with the
assertEscapedlines. Those assertions were added as part of #2400543: Breadcrumb should be term name instead of term id on term edit and delete page. The terms have random machine names though so they are never going to have any special characters that need escaping anyway. So it seems kind of like a bogus assertion. I left it but I figured I should at least call that out!Comment #15
danflanagan8Oops. I made a patch out of the interdiff. Here's the real patch.
Comment #16
nod_The new patch looks good to me, I agree that the xpath version is more readable.
Comment #17
alexpottCommitted and pushed 435dc2011d to 10.0.x and 41b04e45ba to 9.4.x. Thanks!