Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
\Drupal\Tests\WebAssert::buildXPathQuery
has some protection against non scalar values passed into $args
.
There are bits in core which passes in the result of t()
calls, which is an object now.
Proposed resolution
Cast the object to a string when
(method_exists($arg, '__toString')) {
(string) $arg;
}
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#16 | document_that_only-2795543-16.patch | 778 bytes | cebasqueira |
#13 | document_that_only-2795543-13.patch | 779 bytes | cebasqueira |
#11 | document_that_only-2795543-11.patch | 954 bytes | cebasqueira |
#2 | cast_markup_objects_to-2795543-2.patch | 1.27 KB | GoZ |
Comments
Comment #2
GoZ CreditAttribution: GoZ at Centarro commentedI think you are talking about value of args. $args is supposed to be an array, but values of args can be an object (and shouldn't).
Comment #3
dawehnerAt some point we actually decided to put these things into the BC layer only, so we keep our behaviour as vanilla mink as possible. Most of the time actually calling to t() in tests don't really make sense anyway, and you can use the literal string.
Comment #4
Lendude@dawehner yeah I agree, moving this fix to the BC layer makes sense to me if that is an option here.
Comment #5
dawehnerSo what should we do about this one?
Comment #6
klausiHm, I think we should close this as won't fix. Instead of polluting our buildXPathQuery() method we should remove the t() call in the actual test.
Comment #7
dawehnerI agree, maybe though we could improve documentation to make it clear what/how we support things?
Comment #8
klausiOK, documentation improvement sounds good.
Comment #9
valthebaldWebAssert::buildXPathQuery() annotation already specifies that type of $xpath is string. Any other documentation change needed?
Comment #10
klausiYes, the exception message should say something like "Just pass in scalar values for $xpath and remove all t() calls from your test."
Comment #11
cebasqueira CreditAttribution: cebasqueira at CI&T commentedComment #12
klausino, we should no cast the markup object. This patch should only update the exception message, right?
Comment #13
cebasqueira CreditAttribution: cebasqueira at CI&T commentedComment #14
cebasqueira CreditAttribution: cebasqueira at CI&T commentedComment #15
klausiAh sorry, of course we are iterating over $args and not $xpath. So it should be "Just pass in scalar values for $args and remove all t() calls from your test."
Comment #16
cebasqueira CreditAttribution: cebasqueira at CI&T commentedComment #17
dawehnerWorks for me.
Comment #18
alexpottCommitted 16ddd38 and pushed to 8.3.x. Thanks!
Less unnecessary t() calls in tests will be a nice thing.
Comment #20
alexpott