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
#2407801: Views generic field handler does not work with base fields added some code to \Drupal\views\Tests\ViewResultAssertionTrait::assertIdenticalResultsetHelper()
which gets the value of a field directly from the entity contained in the view result, but it does not cast that value to a string like it is supposed to.
Proposed resolution
Cast those values to strings.
Remaining tasks
Review.
User interface changes
Nope.
API changes
Nope.
Data model changes
Nope.
Comment | File | Size | Author |
---|---|---|---|
#8 | interdiff-8.txt | 1.37 KB | amateescu |
#8 | 2922343-8.patch | 3.96 KB | amateescu |
#5 | 2922343-5.patch | 3.28 KB | amateescu |
#5 | 2922343-test-only.patch | 2.49 KB | amateescu |
#2 | 2922343.patch | 813 bytes | amateescu |
Comments
Comment #2
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedVery simple patch.
I'm not sure where we can add a test for this, so pinging @dawehner for help..
Comment #3
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedForgot to actually ping Daniel.
Comment #4
dawehnerWe are already doing stringcasting in all the other cases, so +1 to add it here too!
I can't think of a really good place to add a test for that. The "best" place I was able to find is somewhere in
\Drupal\Tests\views\Kernel\Handler\FieldFieldTest
. Given that it might be worth writing a custom test class for\Drupal\views\Tests\ViewResultAssertionTrait
.Comment #5
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedI finally figured out the problem! When we load entities from the storage, its field values are strings. However, if we change the values to be something else (e.g. integers or booleans) in a
hook_entity_load()
for example, that's whenassertIdenticalResultsetHelper()
breaks without the explicit string casting from #2.Comment #7
dawehnerI've been having the same issue before on some rest issue. Saving and loading an entity isn't producing the exact same types sadly.
The tests looks as expected for me.
I think we should add an explanation here
Comment #8
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedWe were already explaining it a few lines above, just the code was not really doing what the comment was saying :)
Maybe it will be cleaner if we move the comment down a bit?
Comment #9
dawehner+1. Thank you @amateescu!
Comment #10
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedYay, thanks for reviewing again @dawehner :) I forgot to unassign you after the initial feedback..
Comment #13
catch