#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


User interface changes


API changes


Data model changes


Members fund testing for the Drupal project. Drupal Association Learn more


amateescu created an issue. See original summary.

amateescu’s picture

Status: Active » Needs review
813 bytes

Very simple patch.

I'm not sure where we can add a test for this, so pinging @dawehner for help..

amateescu’s picture

Assigned: Unassigned » dawehner

Forgot to actually ping Daniel.

dawehner’s picture

We 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.

amateescu’s picture

I 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 when assertIdenticalResultsetHelper() breaks without the explicit string casting from #2.

The last submitted patch, 5: 2922343-test-only.patch, failed testing. View results

dawehner’s picture

I'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.

+++ b/core/modules/views/src/Tests/ViewResultAssertionTrait.php
@@ -96,7 +96,8 @@ protected function assertIdenticalResultsetHelper($view, $expected_result, $colu
-          $row[$expected_column] = $field->getValue($value, $column);
+          $field_value = $field->getValue($value, $column);
+          $row[$expected_column] = is_array($field_value) ? array_map('strval', $field_value) : (string) $field_value;

I think we should add an explanation here

amateescu’s picture

We 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?

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

+1. Thank you @amateescu!

amateescu’s picture

Assigned: dawehner » Unassigned

Yay, thanks for reviewing again @dawehner :) I forgot to unassign you after the initial feedback..

  • catch committed 892c0f3 on 8.5.x
    Issue #2922343 by amateescu, dawehner: \Drupal\views\Tests\...

  • catch committed 4a3384a on 8.4.x
    Issue #2922343 by amateescu, dawehner: \Drupal\views\Tests\...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.