-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH Call validate on form fields within form
- Loading branch information
1 parent
a4028d0
commit 283d69a
Showing
10 changed files
with
84 additions
and
140 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
use SilverStripe\Model\ArrayData; | ||
use SilverStripe\View\SSViewer; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use SilverStripe\Forms\EmailField; | ||
|
||
class FormTest extends FunctionalTest | ||
{ | ||
|
@@ -1309,4 +1310,67 @@ protected function clean($input) | |
trim($input ?? '') | ||
); | ||
} | ||
|
||
public static function provideValidateFormFields() | ||
{ | ||
return [ | ||
'missing values arent invalid' => [ | ||
'values' => [], | ||
'isValid' => true, | ||
], | ||
'empty values arent invalid' => [ | ||
'values' => [ | ||
'EmailField1' => '', | ||
'EmailField2' => null, | ||
], | ||
'isValid' => true, | ||
], | ||
'any invalid is invalid' => [ | ||
'values' => [ | ||
'EmailField1' => '[email protected]', | ||
'EmailField2' => 'not email', | ||
], | ||
'isValid' => false, | ||
], | ||
'all invalid is invalid' => [ | ||
'values' => [ | ||
'EmailField1' => 'not email', | ||
'EmailField2' => 'not email', | ||
], | ||
'isValid' => false, | ||
], | ||
'all valid is valid' => [ | ||
'values' => [ | ||
'EmailField1' => '[email protected]', | ||
'EmailField2' => '[email protected]', | ||
], | ||
'isValid' => true, | ||
], | ||
]; | ||
} | ||
|
||
#[DataProvider('provideValidateFormFields')] | ||
public function testValidateFormFields(array $values, bool $isValid) | ||
{ | ||
$fieldList = new FieldList([ | ||
$field1 = new EmailField('EmailField1'), | ||
$field2 = new EmailField('EmailField2'), | ||
]); | ||
if (array_key_exists('EmailField1', $values)) { | ||
$field1->setValue($values['EmailField1']); | ||
} | ||
if (array_key_exists('EmailField2', $values)) { | ||
$field2->setValue($values['EmailField2']); | ||
} | ||
$form = new Form(null, 'testForm', $fieldList, new FieldList([/* no actions */])); | ||
|
||
$result = $form->validationResult(); | ||
$this->assertSame($isValid, $result->isValid()); | ||
$messages = $result->getMessages(); | ||
if ($isValid) { | ||
$this->assertEmpty($messages); | ||
} else { | ||
$this->assertNotEmpty($messages); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters