1010
1111class MultiLinkFieldTest extends SapphireTest
1212{
13- public function provideConvertValueToArray (): array
13+ private static function getDataForProvider (): array
1414 {
1515 return [
1616 'empty string ' => [
1717 'value ' => '' ,
1818 'expected ' => [],
1919 ],
20- 'non-comma-separated numeric string ' => [
20+ 'non-comma-separated string ' => [
2121 'value ' => 'this is a string ' ,
2222 'expected ' => ['this is a string ' ],
2323 ],
@@ -29,8 +29,8 @@ public function provideConvertValueToArray(): array
2929 'value ' => '1,2,3,4 ' ,
3030 'expected ' => [1 , 2 , 3 , 4 ],
3131 ],
32- 'comma-separated string with spaces ' => [
33- 'value ' => ' 1,2 , 3, 4 ' ,
32+ 'comma-separated string with whitesapce ' => [
33+ 'value ' => " 1,2 , 3, 4 \n " ,
3434 'expected ' => [1 , 2 , 3 , 4 ],
3535 ],
3636 'number ' => [
@@ -56,6 +56,11 @@ public function provideConvertValueToArray(): array
5656 ];
5757 }
5858
59+ public static function provideConvertValueToArray (): array
60+ {
61+ return MultiLinkFieldTest::getDataForProvider ();
62+ }
63+
5964 /**
6065 * @dataProvider provideConvertValueToArray
6166 */
@@ -66,4 +71,24 @@ public function testConvertValueToArray(mixed $value, array $expected): void
6671 $ reflectionMethod ->setAccessible (true );
6772 $ this ->assertSame ($ expected , $ reflectionMethod ->invoke ($ field , $ value ));
6873 }
74+
75+ public static function provideSetSubmittedValue (): array
76+ {
77+ return array_merge (MultiLinkFieldTest::getDataForProvider (), [
78+ 'comma-separated string with brackets ' => [
79+ 'value ' => '[1,2,3,4] ' ,
80+ 'expected ' => [1 , 2 , 3 , 4 ],
81+ ],
82+ ]);
83+ }
84+
85+ /**
86+ * @dataProvider provideSetSubmittedValue
87+ */
88+ public function testSetSubmittedValue (mixed $ value , array $ expected ): void
89+ {
90+ $ field = new MultiLinkField ('' );
91+ $ field ->setSubmittedValue ($ value );
92+ $ this ->assertSame ($ expected , $ field ->Value ($ value ));
93+ }
6994}
0 commit comments