protected function DateRangeFieldValidationRuleTest::setUp in Field Validation 8
Overrides FieldValidationRuleBase::setUp
File
- tests/
src/ Kernel/ Plugin/ FieldValidationRule/ DateRangeFieldValidationRuleTest.php, line 46
Class
- DateRangeFieldValidationRuleTest
- Tests DateRangeFieldValidationRule.
Namespace
Drupal\Tests\field_validation\Kernel\Plugin\FieldValidationRuleCode
protected function setUp() {
parent::setUp();
$this
->setupTestArticle(self::FIELD_NAME);
$this->ruleSet = $this->ruleSetStorage
->create([
'name' => 'Date_range_test',
'entity_type' => 'node',
'bundle' => 'article',
]);
$this->ruleSet
->addFieldValidationRule([
'id' => self::RULE_ID,
'title' => self::RULE_TITLE,
'weight' => 1,
'field_name' => self::FIELD_NAME,
'column' => 'value',
'error_message' => 'Dates are out of range!',
'data' => [
'min' => '2012-01-01 08:30:00',
'max' => '2013-01-01 08:30:00',
'cycle' => 'global',
],
]);
$this->ruleSet
->save();
$this->entity = $this->nodeStorage
->create([
'type' => 'article',
'title' => 'test',
self::FIELD_NAME => '',
]);
$this->entity
->get(self::FIELD_NAME)
->getFieldDefinition()
->addConstraint('FieldValidationConstraint', [
'ruleset_name' => $this->ruleSet
->getName(),
]);
}