Skip to content

Commit

Permalink
Add test for max and min validation rules (#44444)
Browse files Browse the repository at this point in the history
  • Loading branch information
imanghafoori1 authored Oct 4, 2022
1 parent 92d6509 commit 758b805
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2559,12 +2559,28 @@ public function testValidateMin()
$v = new Validator($trans, ['foo' => '3'], ['foo' => 'Min:3']);
$this->assertFalse($v->passes());

// an equal value qualifies.
$v = new Validator($trans, ['foo' => '3'], ['foo' => 'Numeric|Min:3']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['foo' => 'anc'], ['foo' => 'Min:3']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['foo' => '2'], ['foo' => 'Numeric|Min:3']);
$this->assertFalse($v->passes());

// '2.001' is considered as a float when the "Numeric" rule exists.
$v = new Validator($trans, ['foo' => '2.001'], ['foo' => 'Numeric|Min:3']);
$this->assertFalse($v->passes());

// '2.001' is a string of length 5 in absence of the "Numeric" rule.
$v = new Validator($trans, ['foo' => '2.001'], ['foo' => 'Min:3']);
$this->assertTrue($v->passes());

// '20' is a string of length 2 in absence of the "Numeric" rule.
$v = new Validator($trans, ['foo' => '20'], ['foo' => 'Min:3']);
$this->assertFalse($v->passes());

$v = new Validator($trans, ['foo' => '5'], ['foo' => 'Numeric|Min:3']);
$this->assertTrue($v->passes());

Expand Down Expand Up @@ -2597,6 +2613,18 @@ public function testValidateMax()
$v = new Validator($trans, ['foo' => '211'], ['foo' => 'Numeric|Max:100']);
$this->assertFalse($v->passes());

// an equal value qualifies.
$v = new Validator($trans, ['foo' => '3'], ['foo' => 'Numeric|Max:3']);
$this->assertTrue($v->passes());

// '2.001' is considered as a float when the "Numeric" rule exists.
$v = new Validator($trans, ['foo' => '2.001'], ['foo' => 'Numeric|Max:3']);
$this->assertTrue($v->passes());

// '2.001' is a string of length 5 in absence of the "Numeric" rule.
$v = new Validator($trans, ['foo' => '2.001'], ['foo' => 'Max:3']);
$this->assertFalse($v->passes());

$v = new Validator($trans, ['foo' => '22'], ['foo' => 'Numeric|Max:33']);
$this->assertTrue($v->passes());

Expand Down

0 comments on commit 758b805

Please sign in to comment.