Skip to content

Commit

Permalink
Adds "lowercase" validation rule (#44883)
Browse files Browse the repository at this point in the history
* Adds "lowercase" validation rule

* Update ValidatesAttributes.php

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
timacdonald and taylorotwell authored Nov 8, 2022
1 parent 44391ab commit c3ed678
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,19 @@ public function validateLte($attribute, $value, $parameters)
return $this->getSize($attribute, $value) <= $this->getSize($attribute, $comparedToValue);
}

/**
* Validate that an attribute is lowercase.
*
* @param string $attribute
* @param mixed $value
* @param array<int, int|string> $parameters
* @return bool
*/
public function validateLowercase($attribute, $value, $parameters)
{
return Str::lower($value) === $value;
}

/**
* Validate the MIME type of a file is an image MIME type.
*
Expand Down
27 changes: 27 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1803,6 +1803,33 @@ public function testGreaterThan()
$this->assertTrue($v->passes());
}

public function testLowercase()
{
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, [
'lower' => 'lowercase',
'mixed' => 'MixedCase',
'upper' => 'UPPERCASE',
'lower_multibyte' => 'carácter multibyte',
'mixed_multibyte' => 'carÁcter multibyte',
'upper_multibyte' => 'CARÁCTER MULTIBYTE',
], [
'lower' => 'lowercase',
'mixed' => 'lowercase',
'upper' => 'lowercase',
'lower_multibyte' => 'lowercase',
'mixed_multibyte' => 'lowercase',
'upper_multibyte' => 'lowercase',
]);

$this->assertSame([
'mixed',
'upper',
'mixed_multibyte',
'upper_multibyte',
], $v->messages()->keys());
}

public function testLessThan()
{
$trans = $this->getIlluminateArrayTranslator();
Expand Down

0 comments on commit c3ed678

Please sign in to comment.