Skip to content

Commit

Permalink
EZP-31808: Added conversion from string to int in RelationListValueTr…
Browse files Browse the repository at this point in the history
…ansformer::reverseTransform (#30)
  • Loading branch information
adamwojs authored Aug 21, 2020
1 parent ad68299 commit abe2c76
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace EzSystems\EzPlatformContentForms\Tests\FieldType\DataTransformer;

use eZ\Publish\Core\FieldType\RelationList\Value;
use EzSystems\EzPlatformContentForms\FieldType\DataTransformer\RelationListValueTransformer;
use PHPUnit\Framework\TestCase;

final class RelationListValueTransformerTest extends TestCase
{
/**
* @dataProvider dataProviderForTestReverseTransform
*/
public function testReverseTransform($value, ?Value $expectedValue): void
{
$transformer = new RelationListValueTransformer();

$this->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]),
];
}
}

0 comments on commit abe2c76

Please # to comment.