protected function NumericFieldValidationRuleTest::setUp in Field Validation 8
Overrides FieldValidationRuleBase::setUp
File
- tests/
src/ Kernel/ Plugin/ FieldValidationRule/ NumericFieldValidationRuleTest.php, line 50
Class
- NumericFieldValidationRuleTest
- Tests NumericFieldValidationRule.
Namespace
Drupal\Tests\field_validation\Kernel\Plugin\FieldValidationRuleCode
protected function setUp() {
parent::setUp();
$this->min = -255;
$this->max = 255;
$this
->setupTestArticle(self::FIELD_NAME);
$this->ruleSet = $this->ruleSetStorage
->create([
'name' => 'numeric',
'entity_type' => 'node',
'bundle' => 'article',
]);
$this->ruleSet
->addFieldValidationRule([
'id' => 'numeric_field_validation_rule',
'title' => 'validation rule must be empty',
'weight' => 1,
'field_name' => self::FIELD_NAME,
'column' => 'value',
'error_message' => 'Field is not empty',
'data' => [
'min' => $this->min,
'max' => $this->max,
],
]);
$this->ruleSet
->save();
$this->entity = $this->nodeStorage
->create([
'type' => 'article',
'title' => 'test',
self::FIELD_NAME => $this->min,
]);
$this->entity
->get(self::FIELD_NAME)
->getFieldDefinition()
->addConstraint('FieldValidationConstraint', [
'ruleset_name' => $this->ruleSet
->getName(),
]);
}