You are here

protected function MustBeEmptyFieldValidationRuleTest::setUp in Field Validation 8

Overrides FieldValidationRuleBase::setUp

File

tests/src/Kernel/Plugin/FieldValidationRule/MustBeEmptyFieldValidationRuleTest.php, line 43

Class

MustBeEmptyFieldValidationRuleTest
Tests MustBeEmptyFieldValidationRule.

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' => 'must_be_empty',
    'entity_type' => 'node',
    'bundle' => 'article',
  ]);
  $this->ruleSet
    ->addFieldValidationRule([
    'id' => 'must_be_empty_field_validation_rule',
    'title' => 'validation rule must be empty',
    'weight' => 1,
    'field_name' => self::FIELD_NAME,
    'column' => 'value',
    'error_message' => 'Field is not empty',
  ]);
  $this->ruleSet
    ->save();
  $this->entity = $this->nodeStorage
    ->create([
    'type' => 'article',
    'title' => 'test',
    self::FIELD_NAME => 'I am groot!',
  ]);
  $this->entity
    ->get(self::FIELD_NAME)
    ->getFieldDefinition()
    ->addConstraint('FieldValidationConstraint', [
    'ruleset_name' => $this->ruleSet
      ->getName(),
  ]);
}