.../EntityResource/EntityResourceTestBase.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php index cafb5d8..f2108ed 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php @@ -929,9 +929,17 @@ public function testPost() { // Some top-level keys in the normalization may not be fields on the // entity (for example '_links' and '_embedded' in the HAL normalization). if ($created_entity->hasField($field_name)) { + $field_type = $created_entity->get($field_name)->getFieldDefinition()->getType(); + // Fields are stored in the database, when read they are represented + // as strings in PHP memory. The exception: field types that are + // stored in a serialized way. Hence we need to cast most expected + // field normalizations to strings. + $expected_field_normalization = $field_type !== 'map' + ? static::castToString($field_normalization) + : $field_normalization; // Subset, not same, because we can e.g. send just the target_id for the // bundle in a POST request; the response will include more properties. - $this->assertArraySubset(static::castToString($field_normalization), $created_entity->get($field_name) + $this->assertArraySubset($expected_field_normalization, $created_entity->get($field_name) ->getValue(), TRUE); } } @@ -1190,9 +1198,17 @@ public function testPatch() { // Some top-level keys in the normalization may not be fields on the // entity (for example '_links' and '_embedded' in the HAL normalization). if ($updated_entity->hasField($field_name)) { + $field_type = $updated_entity->get($field_name)->getFieldDefinition()->getType(); + // Fields are stored in the database, when read they are represented + // as strings in PHP memory. The exception: field types that are + // stored in a serialized way. Hence we need to cast most expected + // field normalizations to strings. + $expected_field_normalization = $field_type !== 'map' + ? static::castToString($field_normalization) + : $field_normalization; // Subset, not same, because we can e.g. send just the target_id for the // bundle in a PATCH request; the response will include more properties. - $this->assertArraySubset(static::castToString($field_normalization), $updated_entity->get($field_name)->getValue(), TRUE); + $this->assertArraySubset($expected_field_normalization, $updated_entity->get($field_name)->getValue(), TRUE); } } // Ensure that fields do not get deleted if they're not present in the PATCH