-
Notifications
You must be signed in to change notification settings - Fork 308
/
Copy pathPasswordRuleTest.php
70 lines (48 loc) · 2.58 KB
/
PasswordRuleTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Laravel\Fortify\Tests;
use Illuminate\Support\Str;
use Laravel\Fortify\Rules\Password;
class PasswordRuleTest extends OrchestraTestCase
{
public function test_password_rule()
{
$rule = new Password;
$this->assertTrue($rule->passes('password', 'password'));
$this->assertTrue($rule->passes('password', 234234234));
$this->assertFalse($rule->passes('password', ['foo' => 'bar']));
$this->assertFalse($rule->passes('password', 'secret'));
$this->assertTrue(Str::contains($rule->message(), 'must be at least 8 characters'));
$rule->length(10);
$this->assertFalse($rule->passes('password', 'password'));
$this->assertTrue($rule->passes('password', 'password11'));
$this->assertTrue(Str::contains($rule->message(), 'must be at least 10 characters'));
$rule->length(8)->requireUppercase();
$this->assertFalse($rule->passes('password', 'password'));
$this->assertTrue($rule->passes('password', 'Password'));
$this->assertTrue(Str::contains($rule->message(), 'characters and contain at least one uppercase character'));
$rule->length(8)->requireNumeric();
$this->assertFalse($rule->passes('password', 'Password'));
$this->assertFalse($rule->passes('password', 'password1'));
$this->assertTrue($rule->passes('password', 'Password1'));
$this->assertTrue(Str::contains($rule->message(), 'characters and contain at least one uppercase character and one number'));
}
public function test_password_rule_can_require_special_characters()
{
$rule = new Password;
$rule->length(8)->requireSpecialCharacter();
$this->assertTrue($rule->passes('password', 'password!'));
$this->assertFalse($rule->passes('password', 'password'));
$this->assertTrue(Str::contains($rule->message(), 'must be at least 8 characters'));
$this->assertTrue(Str::contains($rule->message(), 'special character'));
}
public function test_password_rule_can_require_numeric_and_special_characters()
{
$rule = new Password;
$rule->length(10)->requireNumeric()->requireSpecialCharacter();
$this->assertTrue($rule->passes('password', 'password5%'));
$this->assertFalse($rule->passes('password', 'my-password'));
$this->assertTrue(Str::contains($rule->message(), 'must be at least 10 characters'));
$this->assertTrue(Str::contains($rule->message(), 'contain at least one special character'));
$this->assertTrue(Str::contains($rule->message(), 'and one number'));
}
}