1111
1212class MultiLinkFieldTest extends SapphireTest
1313{
14- public static function provideConvertValueToArray (): array
14+ public static function getDataForProvider (): array
1515 {
1616 return [
1717 'empty string ' => [
1818 'value ' => '' ,
1919 'expected ' => [],
2020 ],
21- 'non-comma-separated numeric string ' => [
21+ 'non-comma-separated string ' => [
2222 'value ' => 'this is a string ' ,
2323 'expected ' => ['this is a string ' ],
2424 ],
@@ -30,8 +30,8 @@ public static function provideConvertValueToArray(): array
3030 'value ' => '1,2,3,4 ' ,
3131 'expected ' => [1 , 2 , 3 , 4 ],
3232 ],
33- 'comma-separated string with spaces ' => [
34- 'value ' => ' 1,2 , 3, 4 ' ,
33+ 'comma-separated string with whitesapce ' => [
34+ 'value ' => " 1,2 , 3, 4 \n " ,
3535 'expected ' => [1 , 2 , 3 , 4 ],
3636 ],
3737 'number ' => [
@@ -57,6 +57,11 @@ public static function provideConvertValueToArray(): array
5757 ];
5858 }
5959
60+ public static function provideConvertValueToArray (): array
61+ {
62+ return MultiLinkFieldTest::getDataForProvider ();
63+ }
64+
6065 #[DataProvider('provideConvertValueToArray ' )]
6166 public function testConvertValueToArray (mixed $ value , array $ expected ): void
6267 {
@@ -65,4 +70,22 @@ public function testConvertValueToArray(mixed $value, array $expected): void
6570 $ reflectionMethod ->setAccessible (true );
6671 $ this ->assertSame ($ expected , $ reflectionMethod ->invoke ($ field , $ value ));
6772 }
73+
74+ public static function provideSetSubmittedValue (): array
75+ {
76+ return array_merge (MultiLinkFieldTest::getDataForProvider (), [
77+ 'comma-separated string with brackets ' => [
78+ 'value ' => '[1,2,3,4] ' ,
79+ 'expected ' => [1 , 2 , 3 , 4 ],
80+ ],
81+ ]);
82+ }
83+
84+ #[DataProvider('provideSetSubmittedValue ' )]
85+ public function testSetSubmittedValue (mixed $ value , array $ expected ): void
86+ {
87+ $ field = new MultiLinkField ('' );
88+ $ field ->setSubmittedValue ($ value );
89+ $ this ->assertSame ($ expected , $ field ->getValue ($ value ));
90+ }
6891}
0 commit comments