Closed (outdated)
Project:
Drupal core
Version:
11.x-dev
Component:
phpunit
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
19 Sep 2017 at 00:21 UTC
Updated:
29 Jan 2025 at 20:30 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
tim.plunkettSomething like this?
Not super happy with the statefulness of this approach, open to suggestions.
Comment #3
dawehnerNice functionality and really nice solution!
We could add this asssertion to our WebAssert class if we store the state non on the class but rather locally. Do you think the DX would be worse as a result of that?
Comment #4
tim.plunkettthe original version of this was more like this:
Is that more what you meant, but on webassert? not sure
Comment #5
dawehnerYeah ... what is your thought?
Comment #6
tim.plunkettIf we go that way, it doesn't really make sense to have assertPageReloaded(), I'd just as soon call pageTextNotContains() directly.
And maybe a better name for markCurrentPage() is needed.
Comment #7
tim.plunkettAlso, @tedbow should be credited for this issue, as it was his suggestion in #2764931: Contextual links don't work with 'use-ajax' links
Comment #8
tedbowI like the current way rather than returning the string. I feel like it would be easier to make a mistake. In the current way we could even throw an exception if $pageReloadMarker was never set and 1 of the other 2 functions is called.
Also the way it is not we are actually free to change the way it actually works to mark the page later.
Comment #9
droplet commentedYou could jQuery.once that element. if `jQuery.once === 1`, that's no changes.
** It should be equal to ONE. Two or more and ZERO, the test env is polluted.
Comment #10
dawehnerWouldn't this require jquery once on every page? I think having no extra dependency would be nice.
Comment #11
tim.plunkettGood idea.
Comment #12
droplet commented@dawehner
For Contrib way yes, otherwise it always loaded with any ajax in D8 Core.
From the big picture, it's the best I think.
DOM Manipulation has side effect and jQuery.once is a standard thing in Drupal, every script could exclude it globally :)
About the current patch, I suggest adding an ID to the new DOM and let other scripts could exclude it from/trigger a re-render. (these kinds of scripts: https://www.drupal.org/node/2645250)
(it's also best to use a standard prefix. Probably it should add .hidden to minimize any side effect too)
Comment #13
dawehnerCould we store actually this machine name somewhere on the window ... object maybe?
Comment #14
GrandmaGlassesRopeMan@dawehner - Nice point. I think if we can avoid DOM manipulation all together for this test we'll be better off; maybe
window.Drupal.pageReloadMarker?Comment #15
tim.plunkettThis simplifies the patch in a really great way, and removes the possibility of false positives due to stale state.
Yay statelessness!
Went with
window.Drupal.testPageReloadMarkerComment #16
GrandmaGlassesRopeManMinor note,
evaluateScriptrequires multiline scripts to be wrapped in an IIFE, let's maybe document that?Comment #17
droplet commentedcan we replace EOS to JS? Some editors has JS highlighting :)
Comment #18
tim.plunkettOpened https://github.com/minkphp/Mink/pull/742 to address #16, we shouldn't need to document that.
I switched to JS and PHPStorm immediately picked it up. That's cool, thanks!
Comment #19
dawehnerThis is a much nicer solution now!!!
I think for an actual test coverage it would be nice to have some interactive behaviour going on in the meantime
Comment #20
tedbowre #19 I am not sure we should add interactive behavior to the
testAssertPageNotReloaded()we are testing theassertPageNotReloadednot whether any particular activity does or doesn't reload the page.Maybe as follow up we could look at adding this to current tests that testing our ajax system but I think it is pretty untested with functional javascript tests.
Comment #21
tim.plunkettThe current use cases we have for this are around testing code that returns an AJAX response when JS is enabled, and performs a redirect when not. Usually from a modal. But it's not only intended for that, and I'm hesitant to tie this test to any particular use case.
If you really strongly, we can couple this test to something with modals.
Comment #22
dawehnerMaybe executing some HTTP request using
jQuery.Getto the frontpage or so. It just feels like doing nothing also doesn't really cover it properly.Comment #23
tim.plunkettComment #24
dawehnerI was the pain in the ass, so I should also add the test coverage ... I'm not sure these tests pass, I don't have time right now :(
Comment #26
dawehnerI forgot to add some files ...
This time the tests though also pass.
Comment #27
dawehnerComment #30
tim.plunkettFixed trailing whitespace and moved everything from JTB to WDTB.
Comment #31
tedbowFor both of these test methods should have test that assertion actually fails if the page is/isn't reloaded.
I think this should have @see to
getCurrentPageMarker()also a @see in the other direction.
1. You call
markCurrentPage()to mark the page2. You either call
assertPageNotReloaded()orassertPageReloaded()3. in either case
getCurrentPageMarker()get called.Would it be logical error or a problem in your test if you call
markCurrentPage()2x without calling one of the asserts above?We could maybe avoid some bad tests but actually checking
getCurrentPageMarker()inside to see if it is already marked and throw an exception if it is.Maybe
markCurrentPage()could have parameter$clear_markwhich would default to FALSE but if TRUE would not throw the exception(and not check internally)I just don't know of another case where we have these to interelated test methods and might want help with this because easy to make logic errors in tests and not know what you are actually testing.
Comment #32
tedbowI played around with this some more.
Both of the new assertions don't have a custom message so get an error message like
"Failed asserting that a string is empty."
This is not very helpful. Could we change these to custom messages about the reload state.
If at test calls
assertPageReloaded()without callingmarkCurrentPage()first the assert actually just passes. And we don't have a @see formarkCurrentPage()so it seems reasonable this would happen. Even with the @seeWe could just add the @see but I think it would be better to make sure that does happen.
We could add
WebDriverTestBase::$pageMarkedCalledwhich would default to FALSE and be set to TRUE at the end ofmarkCurrentPage(). Then ingetCurrentPageMarker()which both the new assertions use we could throw an exception or$this->fail()with a message about callingmarkCurrentPage()if $pageMarkedCalled is still FALSE.Comment #36
tim.plunkettThis added to the same spot as #3000762: Add assertNoDuplicateIds to a functional test trait so needed a rebase. Still NW for #31/#32, but marking NR first for a test run
Comment #37
tim.plunkettComment #44
tim.plunkett