You are here

protected function WordsFieldValidationRuleTest::setUp in Field Validation 8

Overrides FieldValidationRuleBase::setUp

File

tests/src/Kernel/Plugin/FieldValidationRule/WordsFieldValidationRuleTest.php, line 46

Class

WordsFieldValidationRuleTest
Tests WordsFieldValidationRule.

Namespace

Drupal\Tests\field_validation\Kernel\Plugin\FieldValidationRule

Code

protected function setUp() {
  parent::setUp();
  $this
    ->setupTestArticle(self::FIELD_NAME);
  $this->ruleSet = $this->ruleSetStorage
    ->create([
    'name' => 'words_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' => 'Words error!',
    'data' => [
      'min' => 5,
      'max' => 10,
    ],
  ]);
  $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(),
  ]);
}