Skip to content

Commit

Permalink
Return a validator provided by the fields instance. Need the password…
Browse files Browse the repository at this point in the history
… fields though as they aren't normally in the blueprint.
  • Loading branch information
jasonvarga committed May 15, 2024
1 parent 04802e5 commit 566cd37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
11 changes: 4 additions & 7 deletions src/Http/Requests/UserRegisterRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\Validator as ValidatorFacade;
use Illuminate\Support\Traits\Localizable;
use Illuminate\Validation\Rules\Password;
use Illuminate\Validation\ValidationException;
Expand Down Expand Up @@ -59,22 +58,20 @@ public function processedValues()
public function validator()
{
$blueprint = User::blueprint();
$blueprint->ensureField('password', ['display' => __('Password')]);
$blueprint->ensureField('password_confirmation', ['display' => __('Password Confirmation')]);

$fields = $blueprint->fields();
$this->submittedValues = $this->valuesWithoutAssetFields($fields);
$this->blueprintFields = $fields->addValues($this->submittedValues);

$fieldRules = $this->blueprintFields
return $this->blueprintFields
->validator()
->withRules([
'email' => ['required', 'email', new UniqueUserValue],
'password' => ['required', 'confirmed', Password::default()],
])
->rules();

// should this not return ->validator() from fieldrules?
// tests would need updated to expect labels instead of handles
return ValidatorFacade::make($this->submittedValues, $fieldRules);
->validator();
}

public function validateResolved()
Expand Down
12 changes: 6 additions & 6 deletions tests/Tags/User/RegisterFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ public function it_wont_register_user_and_renders_errors()
preg_match_all('/<p class="inline-error">(.+)<\/p>/U', $output, $inlineErrors);

$expected = [
'The email field is required.',
'The password field is required.',
'The Email Address field is required.',
'The Password field is required.',
];

$this->assertEmpty($success[1]);
Expand Down Expand Up @@ -191,8 +191,8 @@ public function it_wont_register_user_and_renders_custom_validation_errors()
preg_match_all('/<p class="inline-error">(.+)<\/p>/U', $output, $inlineErrors);

$expected = [
trans('validation.min.string', ['attribute' => 'password', 'min' => 8]), // 'The password must be at least 8 characters.',
trans('validation.required', ['attribute' => 'age']), // 'The age field is required.',
trans('validation.min.string', ['attribute' => 'Password', 'min' => 8]), // 'The password must be at least 8 characters.',
trans('validation.required', ['attribute' => 'Over 18 years of age?']), // 'The age field is required.',
];

$this->assertEmpty($success[1]);
Expand Down Expand Up @@ -311,8 +311,8 @@ public function it_wont_register_user_and_follow_custom_redirect_with_errors()
preg_match_all('/<p class="inline-error">(.+)<\/p>/U', $output, $inlineErrors);

$expected = [
'The email field is required.',
'The password field is required.',
'The Email Address field is required.',
'The Password field is required.',
];

$this->assertEmpty($success[1]);
Expand Down

0 comments on commit 566cd37

Please sign in to comment.