diff --git a/src/Forms/FieldsValidator.php b/src/Forms/FieldsValidator.php index 5a70dd76f7e..9a49e1aa2b7 100644 --- a/src/Forms/FieldsValidator.php +++ b/src/Forms/FieldsValidator.php @@ -3,6 +3,7 @@ namespace SilverStripe\Forms; use SilverStripe\Dev\Deprecation; +use SilverStripe\Forms\Validation\Validator; /** * Validates the internal state of all fields in the form. diff --git a/src/Forms/FileField.php b/src/Forms/FileField.php index a4db0fba7c3..fdeed0a59d7 100644 --- a/src/Forms/FileField.php +++ b/src/Forms/FileField.php @@ -33,7 +33,7 @@ * $actions = new FieldList( * new FormAction('doUpload', 'Upload file') * ); - * $validator = new RequiredFields(['MyName', 'MyFile']); + * $validator = new RequiredFieldsValidator(['MyName', 'MyFile']); * * return new Form($this, 'Form', $fields, $actions, $validator); * } diff --git a/src/Forms/Form.php b/src/Forms/Form.php index 5d25b4f543f..e2c4ed8751e 100644 --- a/src/Forms/Form.php +++ b/src/Forms/Form.php @@ -20,6 +20,8 @@ use SilverStripe\View\AttributesHTML; use SilverStripe\View\SSViewer; use SilverStripe\Model\ModelData; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; +use SilverStripe\Forms\Validation\Validator; /** * Base class for all forms. @@ -297,7 +299,7 @@ public function __construct( $this->setName($name); // Form validation - $this->validator = ($validator) ? $validator : new RequiredFields(); + $this->validator = ($validator) ? $validator : new RequiredFieldsValidator(); $this->validator->setForm($this); // Form error controls diff --git a/src/Forms/GridField/GridFieldDetailForm.php b/src/Forms/GridField/GridFieldDetailForm.php index 544f6221f3c..cff6eaddfd4 100644 --- a/src/Forms/GridField/GridFieldDetailForm.php +++ b/src/Forms/GridField/GridFieldDetailForm.php @@ -15,7 +15,7 @@ use SilverStripe\Core\Injector\Injector; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldsValidator; -use SilverStripe\Forms\Validator; +use SilverStripe\Forms\Validation\Validator; use SilverStripe\ORM\DataList; use SilverStripe\ORM\DataObject; use SilverStripe\Model\ModelData; diff --git a/src/Forms/HasOneRelationFieldInterface.php b/src/Forms/HasOneRelationFieldInterface.php index b520cc9592a..e02451faf7c 100644 --- a/src/Forms/HasOneRelationFieldInterface.php +++ b/src/Forms/HasOneRelationFieldInterface.php @@ -4,7 +4,7 @@ /** * Added to form fields whose values are the ID of a has_one relation - * This is used in RequiredFields validation to check if the value is set + * This is used in RequiredFieldsValidator validation to check if the value is set */ interface HasOneRelationFieldInterface { diff --git a/src/Forms/CompositeValidator.php b/src/Forms/Validation/CompositeValidator.php similarity index 94% rename from src/Forms/CompositeValidator.php rename to src/Forms/Validation/CompositeValidator.php index 8864168d348..5bac807d8b6 100644 --- a/src/Forms/CompositeValidator.php +++ b/src/Forms/Validation/CompositeValidator.php @@ -1,6 +1,6 @@ addValidator(RequiredFields::create(['MyRequiredField'])); + * $compositeValidator->addValidator(RequiredFieldsValidator::create(['MyRequiredField'])); * * return $compositeValidator * } @@ -29,7 +29,7 @@ * * protected function updateCMSCompositeValidator(CompositeValidator $compositeValidator): void * { - * $compositeValidator->addValidator(RequiredFields::create(['AdditionalContent'])); + * $compositeValidator->addValidator(RequiredFieldsValidator::create(['AdditionalContent'])); * } * @deprecated 5.4.0 Will be renamed to SilverStripe\Forms\Validation\CompositeValidator */ @@ -106,7 +106,7 @@ public function validate() } /** - * Note: The existing implementations for the php() method (@see RequiredFields) does not check whether the + * Note: The existing implementations for the php() method (@see RequiredFieldsValidator) does not check whether the * Validator is enabled or not, and it also does not reset the validation result - so, neither does this. * * @param array $data @@ -156,7 +156,7 @@ public function getValidators(): array } /** - * Return all Validators that match a certain class name. EG: RequiredFields::class + * Return all Validators that match a certain class name. EG: RequiredFieldsValidator::class * * The keys for the return array match the keys in the unfiltered array. You cannot assume the keys will be * sequential or that the first key will be ZERO. @@ -181,7 +181,7 @@ public function getValidatorsByType(string $className): array } /** - * Remove all Validators that match a certain class name. EG: RequiredFields::class + * Remove all Validators that match a certain class name. EG: RequiredFieldsValidator::class * * @param string $className * @return CompositeValidator diff --git a/src/Forms/RequiredFields.php b/src/Forms/Validation/RequiredFieldsValidator.php similarity index 98% rename from src/Forms/RequiredFields.php rename to src/Forms/Validation/RequiredFieldsValidator.php index 0ec173f5c1e..51988cd6d17 100644 --- a/src/Forms/RequiredFields.php +++ b/src/Forms/Validation/RequiredFieldsValidator.php @@ -1,6 +1,6 @@ addValidator(RequiredFields::create([ + $validator->addValidator(RequiredFieldsValidator::create([ 'Title' ])); diff --git a/src/Security/LogoutForm.php b/src/Security/LogoutForm.php index 5b12c2c3563..6f4588d9d11 100644 --- a/src/Security/LogoutForm.php +++ b/src/Security/LogoutForm.php @@ -9,7 +9,7 @@ use SilverStripe\Forms\Form; use SilverStripe\Forms\FormAction; use SilverStripe\Forms\HiddenField; -use SilverStripe\Forms\Validator; +use SilverStripe\Forms\Validation\Validator; /** * Log out form to display to users who arrive at 'Security/logout' without a diff --git a/src/Security/Member.php b/src/Security/Member.php index 1e025d5a159..7707df74ee2 100644 --- a/src/Security/Member.php +++ b/src/Security/Member.php @@ -15,7 +15,7 @@ use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\TestMailer; use SilverStripe\Forms\CheckboxField; -use SilverStripe\Forms\CompositeValidator; +use SilverStripe\Forms\Validation\CompositeValidator; use SilverStripe\Forms\ConfirmedPasswordField; use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\FieldList; @@ -682,7 +682,7 @@ public function getMemberPasswordField() /** - * Returns the {@link RequiredFields} instance for the Member object. This + * Returns the {@link RequiredFieldsValidator} instance for the Member object. This * Validator is used when saving a {@link CMSProfileController} or added to * any form responsible for saving a users data. * diff --git a/src/Security/MemberAuthenticator/MemberLoginForm.php b/src/Security/MemberAuthenticator/MemberLoginForm.php index c88df53dc87..8273020748f 100644 --- a/src/Security/MemberAuthenticator/MemberLoginForm.php +++ b/src/Security/MemberAuthenticator/MemberLoginForm.php @@ -10,7 +10,7 @@ use SilverStripe\Forms\HiddenField; use SilverStripe\Forms\LiteralField; use SilverStripe\Forms\PasswordField; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\Forms\TextField; use SilverStripe\Core\Validation\ValidationResult; use SilverStripe\Security\LoginForm as BaseLoginForm; @@ -111,7 +111,7 @@ public function __construct( if (isset($logoutAction)) { $this->setFormAction($logoutAction); } - $this->setValidator(RequiredFields::create(static::config()->get('required_fields'))); + $this->setValidator(RequiredFieldsValidator::create(static::config()->get('required_fields'))); } /** diff --git a/src/Security/Member_Validator.php b/src/Security/Member_Validator.php index 6b979847dd7..7ad2bc354a5 100644 --- a/src/Security/Member_Validator.php +++ b/src/Security/Member_Validator.php @@ -3,7 +3,7 @@ namespace SilverStripe\Security; use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; /** * Member Validator @@ -22,7 +22,7 @@ * - Surname * */ -class Member_Validator extends RequiredFields +class Member_Validator extends RequiredFieldsValidator { /** * Fields that are required by this validator diff --git a/tests/php/Forms/CheckboxFieldTest.php b/tests/php/Forms/CheckboxFieldTest.php index bbd3603492b..574106976f0 100644 --- a/tests/php/Forms/CheckboxFieldTest.php +++ b/tests/php/Forms/CheckboxFieldTest.php @@ -9,7 +9,7 @@ use SilverStripe\ORM\DB; use SilverStripe\Dev\SapphireTest; use SilverStripe\Forms\CheckboxField; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; class CheckboxFieldTest extends SapphireTest { @@ -200,7 +200,7 @@ public function testNoAriaRequired() "form", new FieldList($field), new FieldList(), - new RequiredFields(["RequiredField"]) + new RequiredFieldsValidator(["RequiredField"]) ); $this->assertTrue($field->Required()); diff --git a/tests/php/Forms/CheckboxSetFieldTest.php b/tests/php/Forms/CheckboxSetFieldTest.php index a9c717ae753..2c7e75a3775 100644 --- a/tests/php/Forms/CheckboxSetFieldTest.php +++ b/tests/php/Forms/CheckboxSetFieldTest.php @@ -15,7 +15,7 @@ use SilverStripe\Forms\CheckboxSetField; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\Form; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\Model\ArrayData; class CheckboxSetFieldTest extends SapphireTest @@ -355,7 +355,7 @@ public function testNoAriaRequired() "form", new FieldList($field), new FieldList(), - new RequiredFields(["RequiredField"]) + new RequiredFieldsValidator(["RequiredField"]) ); $this->assertTrue($field->Required()); diff --git a/tests/php/Forms/CompositeFieldTest.php b/tests/php/Forms/CompositeFieldTest.php index f3b22dc711a..d15f60599ab 100644 --- a/tests/php/Forms/CompositeFieldTest.php +++ b/tests/php/Forms/CompositeFieldTest.php @@ -7,7 +7,7 @@ use SilverStripe\Forms\CompositeField; use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\FieldList; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\Forms\TextField; class CompositeFieldTest extends SapphireTest diff --git a/tests/php/Forms/CompositeValidatorTest.php b/tests/php/Forms/CompositeValidatorTest.php index bcd79a41caf..da181e9bbd8 100644 --- a/tests/php/Forms/CompositeValidatorTest.php +++ b/tests/php/Forms/CompositeValidatorTest.php @@ -8,10 +8,10 @@ use SilverStripe\Dev\SapphireTest; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\Form; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\Forms\Tests\ValidatorTest\TestValidator; use SilverStripe\Forms\TextField; -use SilverStripe\Forms\CompositeValidator; +use SilverStripe\Forms\Validation\CompositeValidator; /** * @package framework @@ -40,8 +40,8 @@ protected function getForm(array $fieldNames = []): Form public function testAddValidator(): void { $compositeValidator = new CompositeValidator(); - $compositeValidator->addValidator(new RequiredFields()); - $compositeValidator->addValidator(new RequiredFields()); + $compositeValidator->addValidator(new RequiredFieldsValidator()); + $compositeValidator->addValidator(new RequiredFieldsValidator()); $this->assertCount(2, $compositeValidator->getValidators()); } @@ -76,38 +76,38 @@ public function testSetForm(): void public function testGetValidatorsByType(): void { $compositeValidator = new CompositeValidator(); - $compositeValidator->addValidator(new RequiredFields()); + $compositeValidator->addValidator(new RequiredFieldsValidator()); $compositeValidator->addValidator(new TestValidator()); - $compositeValidator->addValidator(new RequiredFields()); + $compositeValidator->addValidator(new RequiredFieldsValidator()); $compositeValidator->addValidator(new TestValidator()); $this->assertCount(4, $compositeValidator->getValidators()); - $this->assertCount(2, $compositeValidator->getValidatorsByType(RequiredFields::class)); + $this->assertCount(2, $compositeValidator->getValidatorsByType(RequiredFieldsValidator::class)); } public function testRemoveValidatorsByType(): void { $compositeValidator = new CompositeValidator(); - $compositeValidator->addValidator(new RequiredFields()); + $compositeValidator->addValidator(new RequiredFieldsValidator()); $compositeValidator->addValidator(new TestValidator()); - $compositeValidator->addValidator(new RequiredFields()); + $compositeValidator->addValidator(new RequiredFieldsValidator()); $compositeValidator->addValidator(new TestValidator()); $this->assertCount(4, $compositeValidator->getValidators()); - $compositeValidator->removeValidatorsByType(RequiredFields::class); + $compositeValidator->removeValidatorsByType(RequiredFieldsValidator::class); $this->assertCount(2, $compositeValidator->getValidators()); } public function testCanBeCached(): void { $compositeValidator = new CompositeValidator(); - $compositeValidator->addValidator(new RequiredFields()); + $compositeValidator->addValidator(new RequiredFieldsValidator()); $this->assertTrue($compositeValidator->canBeCached()); $compositeValidator = new CompositeValidator(); - $compositeValidator->addValidator(new RequiredFields(['Foor'])); + $compositeValidator->addValidator(new RequiredFieldsValidator(['Foor'])); $this->assertFalse($compositeValidator->canBeCached()); } @@ -121,12 +121,12 @@ public function testFieldIsRequired(): void 'Content', ]; - $requiredFieldsFirst = new RequiredFields( + $requiredFieldsFirst = new RequiredFieldsValidator( [ $fieldNames[0], ] ); - $requiredFieldsSecond = new RequiredFields( + $requiredFieldsSecond = new RequiredFieldsValidator( [ $fieldNames[1], ] @@ -147,8 +147,8 @@ public function testValidate(): void { $compositeValidator = new CompositeValidator(); // Add two separate validators, each with one required field - $compositeValidator->addValidator(new RequiredFields(['Foo'])); - $compositeValidator->addValidator(new RequiredFields(['Bar'])); + $compositeValidator->addValidator(new RequiredFieldsValidator(['Foo'])); + $compositeValidator->addValidator(new RequiredFieldsValidator(['Bar'])); // Setup a form with the fields/data we're testing (a form is a dependency for validation right now) // We'll add three empty fields, but only two of them should be required diff --git a/tests/php/Forms/ConfirmedPasswordFieldTest.php b/tests/php/Forms/ConfirmedPasswordFieldTest.php index 7fb6f643d3f..6c8cee8cf66 100644 --- a/tests/php/Forms/ConfirmedPasswordFieldTest.php +++ b/tests/php/Forms/ConfirmedPasswordFieldTest.php @@ -9,7 +9,7 @@ use SilverStripe\Forms\FieldList; use SilverStripe\Forms\Form; use SilverStripe\Forms\ReadonlyField; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\Security\Member; use SilverStripe\View\SSViewer; use Closure; @@ -466,7 +466,7 @@ public function testChildFieldsAreRequired(bool $canBeEmpty, bool $required, boo $requiredFields[] = 'Test[_Password]'; $requiredFields[] = 'Test[_ConfirmPassword]'; } - $form->setValidator(new RequiredFields($requiredFields)); + $form->setValidator(new RequiredFieldsValidator($requiredFields)); $rendered = $field->Field(); $fieldOneRegex = ']*?required="required"\s+aria-required="true"\s[^>]*\/>'; diff --git a/tests/php/Forms/CurrencyFieldTest.php b/tests/php/Forms/CurrencyFieldTest.php index af08d227595..13543e65751 100644 --- a/tests/php/Forms/CurrencyFieldTest.php +++ b/tests/php/Forms/CurrencyFieldTest.php @@ -6,7 +6,7 @@ use SilverStripe\Dev\SapphireTest; use SilverStripe\Forms\CurrencyField; use SilverStripe\Forms\CurrencyField_Readonly; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\ORM\FieldType\DBCurrency; class CurrencyFieldTest extends SapphireTest diff --git a/tests/php/Forms/DateFieldTest.php b/tests/php/Forms/DateFieldTest.php index 9ac536bc2e3..7f60339a177 100644 --- a/tests/php/Forms/DateFieldTest.php +++ b/tests/php/Forms/DateFieldTest.php @@ -7,7 +7,7 @@ use SilverStripe\Dev\SapphireTest; use SilverStripe\Forms\DateField; use SilverStripe\Forms\DateField_Disabled; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\i18n\i18n; use SilverStripe\ORM\FieldType\DBDate; use SilverStripe\ORM\FieldType\DBDatetime; diff --git a/tests/php/Forms/DatetimeFieldTest.php b/tests/php/Forms/DatetimeFieldTest.php index 68e31a4eac8..4dc5da9e8b4 100644 --- a/tests/php/Forms/DatetimeFieldTest.php +++ b/tests/php/Forms/DatetimeFieldTest.php @@ -9,7 +9,7 @@ use SilverStripe\Forms\FieldList; use SilverStripe\Forms\Form; use SilverStripe\Forms\FormAction; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\Forms\Tests\DatetimeFieldTest\Model; use SilverStripe\i18n\i18n; use SilverStripe\ORM\FieldType\DBDatetime; diff --git a/tests/php/Forms/DropdownFieldTest.php b/tests/php/Forms/DropdownFieldTest.php index 8e4de0e2fbe..2e87284a7c3 100644 --- a/tests/php/Forms/DropdownFieldTest.php +++ b/tests/php/Forms/DropdownFieldTest.php @@ -7,7 +7,7 @@ use SilverStripe\Dev\CSSContentParser; use SilverStripe\Dev\SapphireTest; use SilverStripe\Forms\DropdownField; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\Forms\FormTemplateHelper; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\Form; @@ -574,7 +574,7 @@ public function testRequiredDropdownHasEmptyDefault() "form", new FieldList($field), new FieldList(), - new RequiredFields(["RequiredField"]) + new RequiredFieldsValidator(["RequiredField"]) ); $this->assertTrue($field->getHasEmptyDefault()); diff --git a/tests/php/Forms/EmailFieldTest/TestController.php b/tests/php/Forms/EmailFieldTest/TestController.php index fd01418e34f..a0ae0ca3dc1 100644 --- a/tests/php/Forms/EmailFieldTest/TestController.php +++ b/tests/php/Forms/EmailFieldTest/TestController.php @@ -9,7 +9,7 @@ use SilverStripe\Forms\FieldList; use SilverStripe\Forms\Form; use SilverStripe\Forms\FormAction; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\View\SSViewer; class TestController extends Controller implements TestOnly @@ -54,7 +54,7 @@ public function Form() new FieldList( new FormAction('doSubmit') ), - new RequiredFields( + new RequiredFieldsValidator( 'Email' ) ); diff --git a/tests/php/Forms/FileFieldTest.php b/tests/php/Forms/FileFieldTest.php index 3529b5eea1f..aa863cf049d 100644 --- a/tests/php/Forms/FileFieldTest.php +++ b/tests/php/Forms/FileFieldTest.php @@ -10,7 +10,7 @@ use SilverStripe\Forms\FileField; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\Form; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; class FileFieldTest extends FunctionalTest { @@ -126,7 +126,7 @@ public function testUploadMissingRequiredFile() $fileField = new FileField('cv', 'Upload your CV') ), new FieldList(), - new RequiredFields('cv') + new RequiredFieldsValidator('cv') ); // All fields are filled but for some reason an error occurred when uploading the file => fails $fileFieldValue = [ diff --git a/tests/php/Forms/FormFieldTest.php b/tests/php/Forms/FormFieldTest.php index 647c1adcfec..ba8438c3ffc 100644 --- a/tests/php/Forms/FormFieldTest.php +++ b/tests/php/Forms/FormFieldTest.php @@ -20,7 +20,7 @@ use SilverStripe\Forms\NullableField; use SilverStripe\Forms\PopoverField; use SilverStripe\Forms\PrintableTransformation_TabSet; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\Forms\SelectionGroup; use SilverStripe\Forms\SelectionGroup_Item; use SilverStripe\Forms\Tab; @@ -533,7 +533,7 @@ public function testSetSchemaState() public function testGetSchemaStateWithFormValidation() { $field = new FormField('MyField', 'My Field'); - $validator = new RequiredFields('MyField'); + $validator = new RequiredFieldsValidator('MyField'); $form = new Form(null, 'TestForm', new FieldList($field), new FieldList(), $validator); $form->validationResult(); $schema = $field->getSchemaState(); diff --git a/tests/php/Forms/FormSchemaTest.php b/tests/php/Forms/FormSchemaTest.php index ed78a8ef70c..1cc3a46fbd6 100644 --- a/tests/php/Forms/FormSchemaTest.php +++ b/tests/php/Forms/FormSchemaTest.php @@ -11,7 +11,7 @@ use SilverStripe\Forms\FieldList; use SilverStripe\Forms\Form; use SilverStripe\Forms\TextField; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\Forms\FormAction; use SilverStripe\Forms\PopoverField; use SilverStripe\Forms\FormField; @@ -141,7 +141,7 @@ public function testGetStateWithFieldValidationErrors() { $fields = new FieldList(new TextField('Title')); $actions = new FieldList(); - $validator = new RequiredFields('Title'); + $validator = new RequiredFieldsValidator('Title'); $form = new Form(null, 'TestForm', $fields, $actions, $validator); $form->clearMessage(); $form->loadDataFrom( @@ -240,7 +240,7 @@ public function testSchemaValidation() new CurrencyField("Money") ), new FieldList(), - new RequiredFields('Name') + new RequiredFieldsValidator('Name') ); $formSchema = new FormSchema(); $schema = $formSchema->getSchema($form); diff --git a/tests/php/Forms/FormTest/ControllerWithSpecialSubmittedValueFields.php b/tests/php/Forms/FormTest/ControllerWithSpecialSubmittedValueFields.php index 538261bd6c9..d16d59a8034 100644 --- a/tests/php/Forms/FormTest/ControllerWithSpecialSubmittedValueFields.php +++ b/tests/php/Forms/FormTest/ControllerWithSpecialSubmittedValueFields.php @@ -12,7 +12,7 @@ use SilverStripe\Forms\FormAction; use SilverStripe\Forms\MoneyField; use SilverStripe\Forms\NumericField; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\Forms\TextField; use SilverStripe\Core\Validation\ValidationException; use SilverStripe\Core\Validation\ValidationResult; @@ -69,7 +69,7 @@ public function Form() new FieldList( FormAction::create('doSubmit') ), - new RequiredFields( + new RequiredFieldsValidator( 'SomeRequiredField' ) ); diff --git a/tests/php/Forms/FormTest/TestController.php b/tests/php/Forms/FormTest/TestController.php index a9ca0a1259d..1aac455062d 100644 --- a/tests/php/Forms/FormTest/TestController.php +++ b/tests/php/Forms/FormTest/TestController.php @@ -11,7 +11,7 @@ use SilverStripe\Forms\Form; use SilverStripe\Forms\FormAction; use SilverStripe\Forms\NumericField; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\Forms\TextField; use SilverStripe\Core\Validation\ValidationException; use SilverStripe\Core\Validation\ValidationResult; @@ -66,7 +66,7 @@ public function Form() FormAction::create('doSubmitActionExempt') ->setValidationExempt(true) ), - new RequiredFields( + new RequiredFieldsValidator( 'Email', 'SomeRequiredField' ) diff --git a/tests/php/Forms/GridField/GridFieldDetailFormTest/Person.php b/tests/php/Forms/GridField/GridFieldDetailFormTest/Person.php index c5f33364065..ce97268c0e6 100644 --- a/tests/php/Forms/GridField/GridFieldDetailFormTest/Person.php +++ b/tests/php/Forms/GridField/GridFieldDetailFormTest/Person.php @@ -5,7 +5,7 @@ use SilverStripe\Dev\TestOnly; use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObjectSchema; @@ -67,7 +67,7 @@ public function getCMSFields() public function getCMSValidator() { - return new RequiredFields( + return new RequiredFieldsValidator( [ 'FirstName', 'Surname' diff --git a/tests/php/Forms/GridField/GridFieldTest.php b/tests/php/Forms/GridField/GridFieldTest.php index d80a9a70c62..7dc479356e1 100644 --- a/tests/php/Forms/GridField/GridFieldTest.php +++ b/tests/php/Forms/GridField/GridFieldTest.php @@ -22,7 +22,7 @@ use SilverStripe\Forms\GridField\GridState; use SilverStripe\Forms\GridField\GridState_Component; use SilverStripe\Forms\GridField\GridState_Data; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\Forms\Tests\GridField\GridFieldTest\Cheerleader; use SilverStripe\Forms\Tests\GridField\GridFieldTest\Component; use SilverStripe\Forms\Tests\GridField\GridFieldTest\Component2; @@ -551,7 +551,7 @@ public function testValidationMessageInOutput() $gridField->setMessage(null); // A form that passes validation should not display a validation error in the FieldHolder output. - $form->setValidator(new RequiredFields()); + $form->setValidator(new RequiredFieldsValidator()); $form->validationResult(); $gridfieldOutput = $gridField->FieldHolder(); $this->assertStringNotContainsString('

', $gridfieldOutput); diff --git a/tests/php/Forms/GroupedDropdownFieldTest.php b/tests/php/Forms/GroupedDropdownFieldTest.php index d382afcbe6d..22207dfd9ff 100644 --- a/tests/php/Forms/GroupedDropdownFieldTest.php +++ b/tests/php/Forms/GroupedDropdownFieldTest.php @@ -4,7 +4,7 @@ use SilverStripe\Dev\SapphireTest; use SilverStripe\Forms\GroupedDropdownField; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; class GroupedDropdownFieldTest extends SapphireTest { diff --git a/tests/php/Forms/ListboxFieldTest.php b/tests/php/Forms/ListboxFieldTest.php index b451f97b590..5ef0a1b3832 100644 --- a/tests/php/Forms/ListboxFieldTest.php +++ b/tests/php/Forms/ListboxFieldTest.php @@ -9,7 +9,7 @@ use SilverStripe\Dev\CSSContentParser; use SilverStripe\Dev\SapphireTest; use SilverStripe\Forms\ListboxField; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\Model\ArrayData; use PHPUnit\Framework\Attributes\DataProvider; diff --git a/tests/php/Forms/MoneyFieldTest.php b/tests/php/Forms/MoneyFieldTest.php index d48b393301b..ea136e8be69 100644 --- a/tests/php/Forms/MoneyFieldTest.php +++ b/tests/php/Forms/MoneyFieldTest.php @@ -5,7 +5,7 @@ use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\HiddenField; use SilverStripe\Forms\NumericField; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\Forms\Tests\MoneyFieldTest\CustomSetter_Object; use SilverStripe\Forms\Tests\MoneyFieldTest\TestObject; use SilverStripe\Forms\TextField; diff --git a/tests/php/Forms/NumericFieldTest.php b/tests/php/Forms/NumericFieldTest.php index 6637f3d55b6..641a8153703 100644 --- a/tests/php/Forms/NumericFieldTest.php +++ b/tests/php/Forms/NumericFieldTest.php @@ -4,7 +4,7 @@ use SilverStripe\Dev\SapphireTest; use SilverStripe\Forms\NumericField; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\i18n\i18n; use PHPUnit\Framework\Attributes\DataProvider; diff --git a/tests/php/Forms/OptionsetFieldTest.php b/tests/php/Forms/OptionsetFieldTest.php index 0528e7ed268..04c188d6e5c 100644 --- a/tests/php/Forms/OptionsetFieldTest.php +++ b/tests/php/Forms/OptionsetFieldTest.php @@ -7,7 +7,7 @@ use SilverStripe\Dev\CSSContentParser; use SilverStripe\Dev\SapphireTest; use SilverStripe\Forms\OptionsetField; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\Form; @@ -46,7 +46,7 @@ public function testValidation() "Five" => "Five" ] ); - $validator = new RequiredFields('Test'); + $validator = new RequiredFieldsValidator('Test'); $form = new Form(null, 'Form', new FieldList($field), new FieldList(), $validator); $field->setValue("One"); @@ -60,14 +60,14 @@ public function testValidation() $field->setValue(''); $this->assertFalse($field->validate()->isValid()); - // ... and should not pass "RequiredFields" validation + // ... and should not pass "RequiredFieldsValidator" validation $this->assertFalse($form->validationResult()->isValid()); // null value should pass field-level validation... $field->setValue(null); $this->assertTrue($field->validate()->isValid()); - // ... but should not pass "RequiredFields" validation + // ... but should not pass "RequiredFieldsValidator" validation $this->assertFalse($form->validationResult()->isValid()); // disabled items shouldn't validate @@ -118,7 +118,7 @@ public function testNoAriaRequired() "form", new FieldList($field), new FieldList(), - new RequiredFields(["RequiredField"]) + new RequiredFieldsValidator(["RequiredField"]) ); $this->assertTrue($field->Required()); diff --git a/tests/php/Forms/RequiredFieldsTest.php b/tests/php/Forms/RequiredFieldsValidatorTest.php similarity index 95% rename from tests/php/Forms/RequiredFieldsTest.php rename to tests/php/Forms/RequiredFieldsValidatorTest.php index 1f52c0cb46c..650cedfb776 100644 --- a/tests/php/Forms/RequiredFieldsTest.php +++ b/tests/php/Forms/RequiredFieldsValidatorTest.php @@ -3,7 +3,7 @@ namespace SilverStripe\Forms\Tests; use SilverStripe\Dev\SapphireTest; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\Forms\Form; use SilverStripe\Forms\SearchableDropdownField; use SilverStripe\Forms\TreeDropdownField; @@ -12,7 +12,7 @@ use SilverStripe\Forms\TextField; use SilverStripe\Forms\FieldList; -class RequiredFieldsTest extends SapphireTest +class RequiredFieldsValidatorTest extends SapphireTest { public function testConstructingWithArray() { @@ -23,7 +23,7 @@ public function testConstructingWithArray() 'Image', 'AnotherField' ]; - $requiredFields = new RequiredFields($fields); + $requiredFields = new RequiredFieldsValidator($fields); //check the fields and the array match $this->assertEquals( $fields, @@ -35,7 +35,7 @@ public function testConstructingWithArray() public function testConstructingWithArguments() { //can we construct with arguments? - $requiredFields = new RequiredFields( + $requiredFields = new RequiredFieldsValidator( 'Title', 'Content', 'Image', @@ -57,7 +57,7 @@ public function testConstructingWithArguments() public function testRemoveValidation() { //can we remove all fields at once? - $requiredFields = new RequiredFields( + $requiredFields = new RequiredFieldsValidator( 'Title', 'Content', 'Image', @@ -74,7 +74,7 @@ public function testRemoveValidation() public function testRemoveRequiredField() { //set up the required fields - $requiredFields = new RequiredFields( + $requiredFields = new RequiredFieldsValidator( 'Title', 'Content', 'Image', @@ -117,7 +117,7 @@ public function testRemoveRequiredField() public function testAddRequiredField() { //set up the validator - $requiredFields = new RequiredFields( + $requiredFields = new RequiredFieldsValidator( 'Title' ); //add a field @@ -183,14 +183,14 @@ public function testAddRequiredField() public function testAppendRequiredFields() { //get the validator - $requiredFields = new RequiredFields( + $requiredFields = new RequiredFieldsValidator( 'Title', 'Content', 'Image', 'AnotherField' ); //create another validator with other fields - $otherRequiredFields = new RequiredFields( + $otherRequiredFields = new RequiredFieldsValidator( [ 'ExtraField1', 'ExtraField2' @@ -212,7 +212,7 @@ public function testAppendRequiredFields() "Merging of required fields failed to behave as expected" ); // create the standard validator so we can check duplicates are ignored - $otherRequiredFields = new RequiredFields( + $otherRequiredFields = new RequiredFieldsValidator( 'Title', 'Content', 'Image', @@ -234,7 +234,7 @@ public function testAppendRequiredFields() "Merging of required fields with duplicates failed to behave as expected" ); //add some new fields and some old ones in a strange order - $otherRequiredFields = new RequiredFields( + $otherRequiredFields = new RequiredFieldsValidator( 'ExtraField3', 'Title', 'ExtraField4', @@ -263,7 +263,7 @@ public function testAppendRequiredFields() public function testFieldIsRequired() { //get the validator - $requiredFields = new RequiredFields( + $requiredFields = new RequiredFieldsValidator( $fieldNames = [ 'Title', 'Content', @@ -312,7 +312,7 @@ public function testHasOneRelationFieldInterfaceValidation(string $className) $param = $className === TreeDropdownField::class ? Group::class : Group::get(); $field = new $className('TestField', 'TestField', $param); $form->Fields()->push($field); - $validator = new RequiredFields('TestField'); + $validator = new RequiredFieldsValidator('TestField'); $validator->setForm($form); // blank string and 0 and '0' and array with value of 0 fail required field validation $this->assertFalse($validator->php(['TestField' => ''])); diff --git a/tests/php/Forms/TextFieldTest.php b/tests/php/Forms/TextFieldTest.php index 062867cad19..09d44ef9f22 100644 --- a/tests/php/Forms/TextFieldTest.php +++ b/tests/php/Forms/TextFieldTest.php @@ -4,7 +4,7 @@ use SilverStripe\Dev\SapphireTest; use SilverStripe\Forms\TextField; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\Forms\Tip; use PHPUnit\Framework\Attributes\DataProvider; diff --git a/tests/php/Forms/TextareaFieldTest.php b/tests/php/Forms/TextareaFieldTest.php index fa481b6a6c3..32ee7724aab 100644 --- a/tests/php/Forms/TextareaFieldTest.php +++ b/tests/php/Forms/TextareaFieldTest.php @@ -4,7 +4,7 @@ use SilverStripe\Dev\SapphireTest; use SilverStripe\Forms\TextareaField; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use PHPUnit\Framework\Attributes\DataProvider; class TextareaFieldTest extends SapphireTest diff --git a/tests/php/Forms/TimeFieldTest.php b/tests/php/Forms/TimeFieldTest.php index 35d0e9fdd27..ea915cceb6f 100644 --- a/tests/php/Forms/TimeFieldTest.php +++ b/tests/php/Forms/TimeFieldTest.php @@ -7,7 +7,7 @@ use SilverStripe\Core\Config\Config; use SilverStripe\Dev\SapphireTest; use SilverStripe\Forms\TimeField; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\i18n\i18n; use PHPUnit\Framework\Attributes\DataProvider; use ReflectionMethod; diff --git a/tests/php/Forms/TreeDropdownFieldTest.php b/tests/php/Forms/TreeDropdownFieldTest.php index 012b22b9a32..fbf15de4f1e 100644 --- a/tests/php/Forms/TreeDropdownFieldTest.php +++ b/tests/php/Forms/TreeDropdownFieldTest.php @@ -10,7 +10,7 @@ use SilverStripe\Control\HTTPRequest; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\Form; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\Forms\TreeDropdownField; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\Tests\HierarchyTest\HierarchyOnSubclassTestObject; @@ -61,7 +61,7 @@ public function testGetSchemaValidation(): void $this->assertSame($expected, $field->getSchemaValidation()); // field is required $fieldList = new FieldList([$field]); - $validator = new RequiredFields('TestTree'); + $validator = new RequiredFieldsValidator('TestTree'); new Form(null, null, $fieldList, null, $validator); $expected = [ 'required' => ['extraEmptyValues' => ['0']], diff --git a/tests/php/Forms/UrlFieldTest.php b/tests/php/Forms/UrlFieldTest.php index da55e05e993..03d73b3a728 100644 --- a/tests/php/Forms/UrlFieldTest.php +++ b/tests/php/Forms/UrlFieldTest.php @@ -4,7 +4,7 @@ use SilverStripe\Dev\SapphireTest; use SilverStripe\Forms\UrlField; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use PHPUnit\Framework\Attributes\DataProvider; class UrlFieldTest extends SapphireTest diff --git a/tests/php/Forms/ValidatorTest/TestValidator.php b/tests/php/Forms/ValidatorTest/TestValidator.php index 141c3522112..f5ebf73826f 100644 --- a/tests/php/Forms/ValidatorTest/TestValidator.php +++ b/tests/php/Forms/ValidatorTest/TestValidator.php @@ -4,7 +4,7 @@ use SilverStripe\Dev\TestOnly; use SilverStripe\Forms\Form; -use SilverStripe\Forms\Validator; +use SilverStripe\Forms\Validation\Validator; class TestValidator extends Validator implements TestOnly { diff --git a/tests/php/Security/GroupTest.php b/tests/php/Security/GroupTest.php index 1834f019ed8..0d5846c496a 100644 --- a/tests/php/Security/GroupTest.php +++ b/tests/php/Security/GroupTest.php @@ -5,7 +5,7 @@ use InvalidArgumentException; use SilverStripe\Control\Controller; use SilverStripe\Dev\FunctionalTest; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\Model\List\ArrayList; use SilverStripe\ORM\DataObject; use SilverStripe\Security\Group; @@ -287,10 +287,10 @@ public function testGroupTitleValidation() $newGroup = new Group(); - $validators = $newGroup->getCMSCompositeValidator()->getValidatorsByType(RequiredFields::class); + $validators = $newGroup->getCMSCompositeValidator()->getValidatorsByType(RequiredFieldsValidator::class); $this->assertCount(1, $validators); $validator = array_shift($validators); - $this->assertInstanceOf(RequiredFields::class, $validator); + $this->assertInstanceOf(RequiredFieldsValidator::class, $validator); $this->assertTrue(in_array('Title', $validator->getRequired() ?? [])); $newGroup->Title = $group1->Title;