From bccdfa8d34c27a53fae56ff75512f93c2214ce22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Thu, 20 Aug 2020 09:49:53 +0200 Subject: [PATCH] EZP-31808: Added conversion from string to int in RelationListValueTransformer::reverseTransform --- .../RelationListValueTransformer.php | 1 + .../RelationListValueTransformerTest.php | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/lib/Tests/FieldType/DataTransformer/RelationListValueTransformerTest.php diff --git a/src/lib/FieldType/DataTransformer/RelationListValueTransformer.php b/src/lib/FieldType/DataTransformer/RelationListValueTransformer.php index ef2e505a..9861829d 100644 --- a/src/lib/FieldType/DataTransformer/RelationListValueTransformer.php +++ b/src/lib/FieldType/DataTransformer/RelationListValueTransformer.php @@ -37,6 +37,7 @@ public function reverseTransform($value) $destinationContentIds = explode(',', $value); $destinationContentIds = array_map('trim', $destinationContentIds); + $destinationContentIds = array_map('intval', $destinationContentIds); return new Value($destinationContentIds); } diff --git a/src/lib/Tests/FieldType/DataTransformer/RelationListValueTransformerTest.php b/src/lib/Tests/FieldType/DataTransformer/RelationListValueTransformerTest.php new file mode 100644 index 00000000..7342989f --- /dev/null +++ b/src/lib/Tests/FieldType/DataTransformer/RelationListValueTransformerTest.php @@ -0,0 +1,42 @@ +assertEquals( + $expectedValue, + $transformer->reverseTransform($value) + ); + } + + public function dataProviderForTestReverseTransform(): iterable + { + yield 'null' => [ + null, + null, + ]; + + yield 'optimistic' => [ + '1,2,3,5,8,13', + new Value([1, 2, 3, 5, 8, 13]), + ]; + } +}