1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace spec\Sylius\Component\User\Model; |
15
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
17
|
|
|
use Sylius\Component\User\Model\User; |
18
|
|
|
use Sylius\Component\User\Model\UserInterface; |
19
|
|
|
|
20
|
|
|
final class UserSpec extends ObjectBehavior |
21
|
|
|
{ |
22
|
|
|
function it_implements_user_interface(): void |
23
|
|
|
{ |
24
|
|
|
$this->shouldImplement(UserInterface::class); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
function its_not_verified_by_default(): void |
28
|
|
|
{ |
29
|
|
|
$this->isVerified()->shouldReturn(false); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
function its_verified_at_date_is_mutable(\DateTime $date): void |
33
|
|
|
{ |
34
|
|
|
$this->setVerifiedAt($date); |
35
|
|
|
|
36
|
|
|
$this->getVerifiedAt()->shouldReturn($date); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
function its_verified_when_verified_at_is_not_empty(\DateTime $date): void |
40
|
|
|
{ |
41
|
|
|
$this->setVerifiedAt($date); |
42
|
|
|
|
43
|
|
|
$this->isVerified()->shouldReturn(true); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
function it_has_no_password_requested_at_date_by_default(): void |
47
|
|
|
{ |
48
|
|
|
$this->getPasswordRequestedAt()->shouldReturn(null); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
function its_password_requested_at_date_is_mutable(): void |
52
|
|
|
{ |
53
|
|
|
$date = new \DateTime(); |
54
|
|
|
$this->setPasswordRequestedAt($date); |
55
|
|
|
|
56
|
|
|
$this->getPasswordRequestedAt()->shouldReturn($date); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
function it_should_return_true_if_password_request_is_non_expired(): void |
60
|
|
|
{ |
61
|
|
|
$passwordRequestedAt = new \DateTime('-1 hour'); |
62
|
|
|
$this->setPasswordRequestedAt($passwordRequestedAt); |
63
|
|
|
$ttl = new \DateInterval('P1D'); |
64
|
|
|
|
65
|
|
|
$this->isPasswordRequestNonExpired($ttl)->shouldReturn(true); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
function it_should_return_false_if_password_request_is_expired(): void |
69
|
|
|
{ |
70
|
|
|
$passwordRequestedAt = new \DateTime('-2 hour'); |
71
|
|
|
$this->setPasswordRequestedAt($passwordRequestedAt); |
72
|
|
|
$ttl = new \DateInterval('PT1H'); |
73
|
|
|
|
74
|
|
|
$this->isPasswordRequestNonExpired($ttl)->shouldReturn(false); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
function it_has_email_and_email_canonical(): void |
78
|
|
|
{ |
79
|
|
|
$this->setEmail('[email protected]'); |
80
|
|
|
$this->setEmailCanonical('[email protected]'); |
81
|
|
|
|
82
|
|
|
$this->getEmail()->shouldReturn('[email protected]'); |
83
|
|
|
$this->getEmailCanonical()->shouldReturn('[email protected]'); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
function it_compares_two_users(): void |
87
|
|
|
{ |
88
|
|
|
$this->setEmail('[email protected]'); |
89
|
|
|
$this->setPassword('ADMIN1337'); |
90
|
|
|
|
91
|
|
|
$user = new \Symfony\Component\Security\Core\User\User('[email protected]', 'ADMIN1337'); |
92
|
|
|
$this->isEqualTo($user)->shouldReturn(false); |
93
|
|
|
|
94
|
|
|
$user = new User(); |
95
|
|
|
$user->setEmail('[email protected]'); |
96
|
|
|
$user->setPassword('ADMIN1337'); |
97
|
|
|
$this->isEqualTo($user)->shouldReturn(true); |
98
|
|
|
|
99
|
|
|
$user->setEnabled(true); |
100
|
|
|
$this->isEqualTo($user)->shouldReturn(false); |
101
|
|
|
|
102
|
|
|
$this->setEnabled(true); |
103
|
|
|
$this->isEqualTo($user)->shouldReturn(true); |
104
|
|
|
|
105
|
|
|
$user->setUsername('admin-example'); |
106
|
|
|
$this->isEqualTo($user)->shouldReturn(false); |
107
|
|
|
|
108
|
|
|
$this->setUsername('admin-example'); |
109
|
|
|
$this->isEqualTo($user)->shouldReturn(true); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|