Skip to content

Commit 16d34fe

Browse files
committed
Merge branch '4' into 5.0
2 parents ee74e68 + 428ae35 commit 16d34fe

4 files changed

Lines changed: 85 additions & 4 deletions

File tree

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"silverstripe/recipe-testing": "^4",
2626
"silverstripe/standards": "^1",
2727
"silverstripe/documentation-lint": "^1",
28+
"silverstripe/siteconfig": "^6",
2829
"squizlabs/php_codesniffer": "^3",
2930
"phpstan/extension-installer": "^1.3"
3031
},

src/Form/MultiLinkField.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ public function setValue(mixed $value, $data = null): static
2626
return parent::setValue($ids, $data);
2727
}
2828

29+
public function setSubmittedValue($value, $data = null)
30+
{
31+
if (is_string($value)) {
32+
$value = rtrim(ltrim($value, '['), ']');
33+
}
34+
return $this->setValue($value, $data);
35+
}
36+
2937
public function getSchemaDataDefaults(): array
3038
{
3139
$data = parent::getSchemaDataDefaults();
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
@retry @job2
2+
Feature: Create Links in LinkField and MultiLinkField on SiteConfig
3+
As a content editor
4+
I want to add links to SiteConfig which has a slightly different EditForm to SiteTree
5+
6+
Background:
7+
Given I add an extension "SilverStripe\FrameworkTest\LinkField\Extensions\LinkPageExtension" to the "SilverStripe\SiteConfig\SiteConfig" class
8+
And I go to "/dev/build?flush"
9+
And I am logged in with "ADMIN" permissions
10+
And I go to "/admin/settings"
11+
12+
Scenario: I can update and save single and multi link fields
13+
14+
Given I should see the "#Form_EditForm_HasOneLink" element
15+
And I should see the "#Form_EditForm_HasManyLinks" element
16+
17+
# Saving empty fields works
18+
When I press the "Save" button
19+
And I wait for 2 seconds
20+
Then I should see a "Saved" success toast
21+
22+
# Saving populated fields works
23+
When I click on the "[data-field-id='Form_EditForm_HasOneLink'] button" element
24+
Then I should see "Phone number" in the "[data-field-id='Form_EditForm_HasOneLink'] .dropdown-item:nth-of-type(3)" element
25+
When I click on the "[data-field-id='Form_EditForm_HasOneLink'] .dropdown-item:nth-of-type(3)" element
26+
And I wait for 5 seconds
27+
Then I should see "Phone number" in the ".modal-header" element
28+
Then I fill in "LinkText" with "Phone"
29+
Then I fill in "Phone" with "12345678"
30+
And I should not see "Open in new window" in the ".modal-content" element
31+
And I press the "Create link" button
32+
And I wait for 2 seconds
33+
34+
When I click on the "[data-field-id='Form_EditForm_HasManyLinks'] button" element
35+
Then I should see "Phone number" in the "[data-field-id='Form_EditForm_HasManyLinks'] .dropdown-item:nth-of-type(5)" element
36+
When I click on the "[data-field-id='Form_EditForm_HasManyLinks'] .dropdown-item:nth-of-type(5)" element
37+
And I wait for 5 seconds
38+
Then I should see "Phone number" in the ".modal-header" element
39+
Then I fill in "LinkText" with "Phone"
40+
Then I fill in "Phone" with "87654321"
41+
And I should not see "Open in new window" in the ".modal-content" element
42+
And I press the "Create link" button
43+
And I wait for 2 seconds
44+
45+
When I press the "Save" button
46+
And I wait for 2 seconds
47+
Then I should see a "Saved" success toast
48+
And I should see "12345678"
49+
And I should see "87654321"

tests/php/Form/MultiLinkFieldTest.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
class 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

Comments
 (0)