You are here

public function IntegerFieldValidationTest::testInteger in Field Validation 8

Test IntegerFieldValidationRule.

File

tests/src/Kernel/Plugin/FieldValidationRule/IntegerFieldValidationTest.php, line 92

Class

IntegerFieldValidationTest
Tests IntegerFieldValidationRule.

Namespace

Drupal\Tests\field_validation\Kernel\Plugin\FieldValidationRule

Code

public function testInteger() {

  // Test above maximum.
  $this
    ->assertConstraintFail($this->entity, self::FIELD_NAME, abs(($this->max + 1) * 10), $this->ruleSet);

  // Test below minimum.
  $this
    ->assertConstraintFail($this->entity, self::FIELD_NAME, ($this->min - 1) * 10, $this->ruleSet);

  // Test not integer.
  $this
    ->assertConstraintFail($this->entity, self::FIELD_NAME, 'TestS', $this->ruleSet);

  // Test between minimum and maximum.
  $this
    ->assertConstraintPass($this->entity, self::FIELD_NAME, 150);
  $this
    ->assertConstraintPass($this->entity, self::FIELD_NAME, -150);

  // Test floats.
  $this
    ->assertConstraintFail($this->entity, self::FIELD_NAME, 1.2345, $this->ruleSet);
  $this
    ->assertConstraintFail($this->entity, self::FIELD_NAME, 1230.0, $this->ruleSet);
  $this
    ->assertConstraintFail($this->entity, self::FIELD_NAME, 7.0E-18, $this->ruleSet);

  // Test at minimum.
  $this
    ->assertConstraintPass($this->entity, self::FIELD_NAME, $this->min);

  // Test at maximum.
  $this
    ->assertConstraintPass($this->entity, self::FIELD_NAME, $this->max);
}