diff --git a/src/Illuminate/Validation/Concerns/ReplacesAttributes.php b/src/Illuminate/Validation/Concerns/ReplacesAttributes.php index abd5ba154a5c..ef9bfaf6bca3 100644 --- a/src/Illuminate/Validation/Concerns/ReplacesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ReplacesAttributes.php @@ -938,7 +938,7 @@ protected function replaceDoesntContain($message, $attribute, $rule, $parameters */ private function replaceWhileKeepingCase(string $message, array $mapping): string { - $fn = [Str::lower(...), Str::upper(...), Str::ucfirst(...)]; + $fn = [fn ($v) => $v, Str::upper(...), Str::ucfirst(...)]; $cases = array_reduce( array_keys($mapping), diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index b6ec5ac6722f..cc0df653d4d9 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -639,6 +639,12 @@ public function testCapitalizedDisplayableValuesAreReplaced() $v->messages()->setFormat(':message'); $this->assertSame('The foo field must be accepted when BAR is AAA.', $v->messages()->first('foo')); + $trans = $this->getIlluminateArrayTranslator(); + $trans->addLines(['validation.accepted_if' => 'The :attribute field must be accepted when :other is :value.'], 'en'); + $v = new Validator($trans, ['foo' => 'no', 'bar' => 'aAa'], ['foo' => 'accepted_if:bar,aAa']); + $this->assertFalse($v->passes()); + $this->assertSame('The foo field must be accepted when bar is aAa.', $v->messages()->first('foo')); + // in_array $trans = $this->getIlluminateArrayTranslator(); $trans->addLines(['validation.in_array' => 'The value of :attribute does not exist in :Other.'], 'en'); @@ -715,6 +721,12 @@ public function testCapitalizedDisplayableValuesAreReplaced() $this->assertFalse($v->passes()); $this->assertSame('The last field is required unless FIRST is in TAYLOR, SVEN.', $v->messages()->first('last')); + $trans = $this->getIlluminateArrayTranslator(); + $trans->addLines(['validation.required_unless' => 'The :attribute field is required unless :other is in :values.'], 'en'); + $v = new Validator($trans, ['firstName' => 'dAyle', 'lastName' => ''], ['lastName' => 'RequiredUnless:firstName,tAylor,sVen']); + $this->assertFalse($v->passes()); + $this->assertSame('The last name field is required unless first name is in tAylor, sVen.', $v->messages()->first('lastName')); + // required_with $trans = $this->getIlluminateArrayTranslator(); $trans->addLines(['validation.required_with' => 'The :attribute field is required when :Values is present.'], 'en'); @@ -753,6 +765,12 @@ public function testCapitalizedDisplayableValuesAreReplaced() $v = new Validator($trans, ['url' => 'laravel.com'], ['url' => 'starts_with:http,https']); $this->assertFalse($v->passes()); $this->assertSame('The url must start with one of the following values HTTP, HTTPS', $v->messages()->first('url')); + + $trans = $this->getIlluminateArrayTranslator(); + $trans->addLines(['validation.starts_with' => 'The :attribute must start with one of the following values :values'], 'en'); + $v = new Validator($trans, ['url' => 'laravel.com'], ['url' => 'starts_with:hTtp,hTtps']); + $this->assertFalse($v->passes()); + $this->assertSame('The url must start with one of the following values hTtp, hTtps', $v->messages()->first('url')); } public function testInputIsReplacedByItsDisplayableValue()