You are here

public function UniqueFieldValidationRuleTest::testSomething in Field Validation 8

Tests uniqueness of the value depending on scope.

File

tests/src/Kernel/Plugin/FieldValidationRule/UniqueFieldValidationRuleTest.php, line 132

Class

UniqueFieldValidationRuleTest
Tests UniqueFieldValidationRule.

Namespace

Drupal\Tests\field_validation\Kernel\Plugin\FieldValidationRule

Code

public function testSomething() {
  $this
    ->assertConstraintFail($this->entity, self::FIELD_NAME, '1337', $this->ruleSet);
  $this
    ->assertConstraintPass($this->entity, self::FIELD_NAME, '9001');
  $this
    ->assertConstraintPass($this->entityOtherBundle, self::FIELD_NAME, '9001');
  $this
    ->assertConstraintPass($this->entityOtherBundle, self::FIELD_NAME, '1337');
  $this
    ->updateSettings([
    'scope' => 'entity',
  ], self::RULE_ID, self::RULE_TITLE, $this->ruleSet, self::FIELD_NAME);
  $this
    ->assertConstraintPass($this->entity, self::FIELD_NAME, '9001');
  $this
    ->assertConstraintFail($this->entity, self::FIELD_NAME, '1337', $this->ruleSet);
}