Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/Validation/Concerns/ReplacesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
18 changes: 18 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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()
Expand Down
Loading