Skip to content

Commit

Permalink
MNT Add custom validator for test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabina Talipova committed Nov 9, 2023
1 parent a5aeaa3 commit 74b06c1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
12 changes: 12 additions & 0 deletions code/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use SilverStripe\Versioned\Versioned;
use RelationFieldsTestPage;
use GridFieldTestPage;
use SilverStripe\Forms\CompositeValidator;
use SilverStripe\Forms\RequiredFields;

/**
*
Expand Down Expand Up @@ -100,6 +102,16 @@ public function getCMSFields()
return $fields;
}

public function getCMSCompositeValidator(): CompositeValidator
{
$validator = parent::getCMSCompositeValidator();
$validator->addValidator(RequiredFields::create([
'Name',
]));

return $validator;
}

public function validate()
{
$result = parent::validate();
Expand Down
11 changes: 11 additions & 0 deletions code/Employee.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace SilverStripe\FrameworkTest\Model;

use SilverStripe\Assets\Image;
use SilverStripe\Forms\CompositeValidator;
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;
Expand Down Expand Up @@ -141,6 +143,15 @@ public function requireDefaultRecords()
srand();
}

public function getCMSCompositeValidator(): CompositeValidator
{
$validator = parent::getCMSCompositeValidator();
$validator->addValidator(RequiredFields::create([
'Name',
]));
return $validator;
}

public function validate()
{
$result = parent::validate();
Expand Down

0 comments on commit 74b06c1

Please sign in to comment.