From 008a4dd49c3a13343137d2bc43297e62006c7f29 Mon Sep 17 00:00:00 2001 From: Michael Nabil <46572405+michaelnabil230@users.noreply.github.com> Date: Mon, 14 Nov 2022 15:15:06 +0200 Subject: [PATCH] Adds `uppercase` validation rule (#44918) --- .../Concerns/ValidatesAttributes.php | 13 +++++++++ tests/Validation/ValidationValidatorTest.php | 27 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php index 25ec6a6896d3..cc9985e631c6 100644 --- a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php @@ -1171,6 +1171,19 @@ public function validateLowercase($attribute, $value, $parameters) return Str::lower($value) === $value; } + /** + * Validate that an attribute is uppercase. + * + * @param string $attribute + * @param mixed $value + * @param array $parameters + * @return bool + */ + public function validateUppercase($attribute, $value, $parameters) + { + return Str::upper($value) === $value; + } + /** * Validate the MIME type of a file is an image MIME type. * diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index ce7fc2d0d3a6..73783c2b9881 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -1830,6 +1830,33 @@ public function testLowercase() ], $v->messages()->keys()); } + public function testUppercase() + { + $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' => 'uppercase', + 'mixed' => 'uppercase', + 'upper' => 'uppercase', + 'lower_multibyte' => 'uppercase', + 'mixed_multibyte' => 'uppercase', + 'upper_multibyte' => 'uppercase', + ]); + + $this->assertSame([ + 'lower', + 'mixed', + 'lower_multibyte', + 'mixed_multibyte', + ], $v->messages()->keys()); + } + public function testLessThan() { $trans = $this->getIlluminateArrayTranslator();