MNT Add custom validator for test cases

This commit is contained in:
Sabina Talipova 2023-11-02 13:29:31 +13:00
parent a5aeaa3380
commit 3f03425c67
2 changed files with 10 additions and 14 deletions

View File

@ -13,6 +13,7 @@ use SilverStripe\Versioned\RecursivePublishable;
use SilverStripe\Versioned\Versioned;
use RelationFieldsTestPage;
use GridFieldTestPage;
use SilverStripe\Forms\RequiredFields;
/**
*
@ -100,15 +101,11 @@ class Company extends DataObject
return $fields;
}
public function validate()
public function getCMSValidator()
{
$result = parent::validate();
if (!$this->Name) {
$result->addFieldError('Name', 'Name is required');
}
return $result;
return new RequiredFields(
['Name']
);
}
public function DynamicProperty()

View File

@ -5,6 +5,7 @@ namespace SilverStripe\FrameworkTest\Model;
use SilverStripe\Assets\Image;
use SilverStripe\Forms\EmailField;
use SilverStripe\Forms\NumericField;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\Connect\MySQLSchemaManager;
use SilverStripe\ORM\DataObject;
@ -141,13 +142,11 @@ class Employee extends DataObject
srand();
}
public function validate()
public function getCMSValidator()
{
$result = parent::validate();
if (!$this->Name) {
$result->addFieldError('Name', '"Name" can\'t be blank');
}
return $result;
return new RequiredFields(
['Name']
);
}
/**