Skip to content

Commit

Permalink
API Rename validator classes
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Dec 4, 2024
1 parent 2fcf68a commit dbacee6
Show file tree
Hide file tree
Showing 38 changed files with 92 additions and 92 deletions.
10 changes: 5 additions & 5 deletions src/Forms/CompositeValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* {
* $compositeValidator = parent::getCMSCompositeValidator();
*
* $compositeValidator->addValidator(RequiredFields::create(['MyRequiredField']));
* $compositeValidator->addValidator(RequiredFieldsValidator::create(['MyRequiredField']));
*
* return $compositeValidator
* }
Expand All @@ -28,7 +28,7 @@
*
* protected function updateCMSCompositeValidator(CompositeValidator $compositeValidator): void
* {
* $compositeValidator->addValidator(RequiredFields::create(['AdditionalContent']));
* $compositeValidator->addValidator(RequiredFieldsValidator::create(['AdditionalContent']));
* }
*/
class CompositeValidator extends Validator
Expand Down Expand Up @@ -100,7 +100,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
Expand Down Expand Up @@ -150,7 +150,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.
Expand All @@ -175,7 +175,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
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/FileField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
* }
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/HasOneRelationFieldInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Validation is performed on a field by field basis through
* {@link FormField::validate}.
*/
class RequiredFields extends Validator
class RequiredFieldsValidator extends Validator
{

/**
Expand Down Expand Up @@ -193,7 +193,7 @@ public function removeRequiredField($field)
/**
* Add {@link RequiredField} objects together
*
* @param RequiredFields $requiredFields
* @param RequiredFieldsValidator $requiredFields
* @return $this
*/
public function appendRequiredFields($requiredFields)
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function removeValidation()
/**
* When Validators are set on the form, it can affect whether or not the form cannot be cached.
*
* @see RequiredFields for an example of when you might be able to cache your form.
* @see RequiredFieldsValidator for an example of when you might be able to cache your form.
*
* @return bool
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Security/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use SilverStripe\Forms\HTMLEditor\HTMLEditorConfig;
use SilverStripe\Forms\ListboxField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;
use SilverStripe\Forms\Tab;
use SilverStripe\Forms\TabSet;
use SilverStripe\Forms\TextareaField;
Expand Down Expand Up @@ -559,7 +559,7 @@ public function getCMSCompositeValidator(): CompositeValidator
{
$validator = parent::getCMSCompositeValidator();

$validator->addValidator(RequiredFields::create([
$validator->addValidator(RequiredFieldsValidator::create([
'Title'
]));

Expand Down
2 changes: 1 addition & 1 deletion src/Security/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
4 changes: 2 additions & 2 deletions src/Security/MemberAuthenticator/MemberLoginForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use SilverStripe\Forms\HiddenField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\PasswordField;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;
use SilverStripe\Forms\TextField;
use SilverStripe\Core\Validation\ValidationResult;
use SilverStripe\Security\LoginForm as BaseLoginForm;
Expand Down Expand Up @@ -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')));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Security/Member_Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace SilverStripe\Security;

use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;

/**
* Member Validator
Expand All @@ -22,7 +22,7 @@
* - Surname
* </code>
*/
class Member_Validator extends RequiredFields
class Member_Validator extends RequiredFieldsValidator
{
/**
* Fields that are required by this validator
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Forms/CheckboxFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use SilverStripe\ORM\DB;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;

class CheckboxFieldTest extends SapphireTest
{
Expand Down Expand Up @@ -200,7 +200,7 @@ public function testNoAriaRequired()
"form",
new FieldList($field),
new FieldList(),
new RequiredFields(["RequiredField"])
new RequiredFieldsValidator(["RequiredField"])
);
$this->assertTrue($field->Required());

Expand Down
4 changes: 2 additions & 2 deletions tests/php/Forms/CheckboxSetFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use SilverStripe\Forms\CheckboxSetField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;
use SilverStripe\Model\ArrayData;

class CheckboxSetFieldTest extends SapphireTest
Expand Down Expand Up @@ -355,7 +355,7 @@ public function testNoAriaRequired()
"form",
new FieldList($field),
new FieldList(),
new RequiredFields(["RequiredField"])
new RequiredFieldsValidator(["RequiredField"])
);
$this->assertTrue($field->Required());

Expand Down
2 changes: 1 addition & 1 deletion tests/php/Forms/CompositeFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use SilverStripe\Forms\CompositeField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;
use SilverStripe\Forms\TextField;

class CompositeFieldTest extends SapphireTest
Expand Down
30 changes: 15 additions & 15 deletions tests/php/Forms/CompositeValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;
use SilverStripe\Forms\Tests\ValidatorTest\TestValidator;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\CompositeValidator;
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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());
}
Expand All @@ -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],
]
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Forms/ConfirmedPasswordFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\ReadonlyField;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;
use SilverStripe\Security\Member;
use SilverStripe\View\SSViewer;
use Closure;
Expand Down Expand Up @@ -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 = '<input\s+type="password"\s+name="Test\[_Password\]"\s[^>]*?required="required"\s+aria-required="true"\s[^>]*\/>';
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Forms/CurrencyFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\CurrencyField;
use SilverStripe\Forms\CurrencyField_Readonly;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;
use SilverStripe\ORM\FieldType\DBCurrency;

class CurrencyFieldTest extends SapphireTest
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Forms/DateFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\DateField;
use SilverStripe\Forms\DateField_Disabled;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;
use SilverStripe\i18n\i18n;
use SilverStripe\ORM\FieldType\DBDate;
use SilverStripe\ORM\FieldType\DBDatetime;
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Forms/DatetimeFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;
use SilverStripe\Forms\Tests\DatetimeFieldTest\Model;
use SilverStripe\i18n\i18n;
use SilverStripe\ORM\FieldType\DBDatetime;
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Forms/DropdownFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use SilverStripe\Dev\CSSContentParser;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;
use SilverStripe\Forms\FormTemplateHelper;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
Expand Down Expand Up @@ -574,7 +574,7 @@ public function testRequiredDropdownHasEmptyDefault()
"form",
new FieldList($field),
new FieldList(),
new RequiredFields(["RequiredField"])
new RequiredFieldsValidator(["RequiredField"])
);

$this->assertTrue($field->getHasEmptyDefault());
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Forms/EmailFieldTest/TestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;
use SilverStripe\View\SSViewer;

class TestController extends Controller implements TestOnly
Expand Down Expand Up @@ -54,7 +54,7 @@ public function Form()
new FieldList(
new FormAction('doSubmit')
),
new RequiredFields(
new RequiredFieldsValidator(
'Email'
)
);
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Forms/FileFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use SilverStripe\Forms\FileField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;

class FileFieldTest extends FunctionalTest
{
Expand Down Expand Up @@ -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 = [
Expand Down
Loading

0 comments on commit dbacee6

Please sign in to comment.