Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rcknr committed Nov 6, 2023
1 parent 6d90aac commit ade1a1e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Validation/Rules/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public function symbols()
/**
* Specify additional validation rules that should be merged with the default rules during validation.
*
* @param string|array $rules
* @param string|array|\Closure $rules
* @return $this
*/
public function rules($rules)
Expand Down
64 changes: 45 additions & 19 deletions tests/Validation/ValidationPasswordRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testConditional()
});

$this->fails($rule, ['aaaaaaaa', '11111111'], [
'The my password must contain at least one symbol.',
'validation.password.symbols',
]);

$is_privileged_user = false;
Expand All @@ -64,7 +64,7 @@ public function testConditional()
public function testMixedCase()
{
$this->fails(Password::min(2)->mixedCase(), ['nn', 'MM'], [
'The my password must contain at least one uppercase and one lowercase letter.',
'validation.password.mixed',
]);

$this->passes(Password::min(2)->mixedCase(), ['Nn', 'Mn', 'âA']);
Expand All @@ -73,7 +73,7 @@ public function testMixedCase()
public function testLetters()
{
$this->fails(Password::min(2)->letters(), ['11', '22', '^^', '``', '**'], [
'The my password must contain at least one letter.',
'validation.password.letters',
]);

$this->passes(Password::min(2)->letters(), ['1a', 'b2', 'â1', '1 京都府']);
Expand All @@ -82,7 +82,7 @@ public function testLetters()
public function testNumbers()
{
$this->fails(Password::min(2)->numbers(), ['aa', 'bb', ' a', '京都府'], [
'The my password must contain at least one number.',
'validation.password.numbers',
]);

$this->passes(Password::min(2)->numbers(), ['1a', 'b2', '00', '京都府 1']);
Expand All @@ -99,7 +99,7 @@ public function testDefaultRules()
public function testSymbols()
{
$this->fails(Password::min(2)->symbols(), ['ab', '1v'], [
'The my password must contain at least one symbol.',
'validation.password.symbols',
]);

$this->passes(Password::min(2)->symbols(), ['n^d', 'd^!', 'âè$', '金廿土弓竹中;']);
Expand All @@ -116,7 +116,7 @@ public function testUncompromised()
'12345678',
'nuno',
], [
'The given my password has appeared in a data leak. Please choose a different my password.',
'validation.password.uncompromised',
]);

$this->passes(Password::min(2)->uncompromised(9999999), [
Expand Down Expand Up @@ -146,22 +146,22 @@ public function testMessagesOrder()

$this->fails($makeRules(), ['foo', 'azdazd'], [
'validation.min.string',
'The my password must contain at least one uppercase and one lowercase letter.',
'The my password must contain at least one number.',
'validation.password.mixed',
'validation.password.numbers',
]);

$this->fails($makeRules(), ['1231231'], [
'validation.min.string',
'The my password must contain at least one uppercase and one lowercase letter.',
'validation.password.mixed',
]);

$this->fails($makeRules(), ['4564654564564'], [
'The my password must contain at least one uppercase and one lowercase letter.',
'validation.password.mixed',
]);

$this->fails($makeRules(), ['aaaaaaaaa', 'TJQSJQSIUQHS'], [
'The my password must contain at least one uppercase and one lowercase letter.',
'The my password must contain at least one number.',
'validation.password.mixed',
'validation.password.numbers',
]);

$this->passes($makeRules(), ['4564654564564Abc']);
Expand All @@ -174,26 +174,26 @@ public function testMessagesOrder()

$this->fails($makeRules(), ['foo', 'azdazd'], [
'validation.min.string',
'The my password must contain at least one symbol.',
'validation.password.symbols',
]);

$this->fails($makeRules(), ['1231231'], [
'validation.min.string',
'The my password must contain at least one letter.',
'The my password must contain at least one symbol.',
'validation.password.letters',
'validation.password.symbols',
]);

$this->fails($makeRules(), ['aaaaaaaaa', 'TJQSJQSIUQHS'], [
'The my password must contain at least one symbol.',
'validation.password.symbols',
]);

$this->fails($makeRules(), ['4564654564564'], [
'The my password must contain at least one letter.',
'The my password must contain at least one symbol.',
'validation.password.letters',
'validation.password.symbols',
]);

$this->fails($makeRules(), ['abcabcabc!'], [
'The given my password has appeared in a data leak. Please choose a different my password.',
'validation.password.uncompromised',
]);

$v = new Validator(
Expand Down Expand Up @@ -269,6 +269,32 @@ public function testItPassesWithValidDataIfTheSameValidationRulesAreReused()
$this->assertTrue($v1->passes());
}

public function testCustomMessages()
{
$rules = [
'my_password' => Password::min(6)->letters(),
];

$messages = [
'min' => 'Message for validating length',
'password.letters' => 'Message for validating letters',
];

$v = new Validator(
resolve('translator'),
['my_password' => '1234'],
$rules,
$messages,
);

$this->assertFalse($v->passes());

$this->assertSame(
[ 'my_password' => array_values($messages) ],
$v->messages()->toArray()
);
}

public function testPassesWithCustomRules()
{
$closureRule = function ($attribute, $value, $fail) {
Expand Down

0 comments on commit ade1a1e

Please sign in to comment.