Completed
Push — master ( 4a505f...c8d6d6 )
by Kamil
16:26 queued 07:06
created

iShouldBeNotifiedThatEmailWithResetInstructionWasSent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 Sylius\Behat\Context\Ui\Shop;
15
16
use Behat\Behat\Context\Context;
17
use Sylius\Behat\NotificationType;
18
use Sylius\Behat\Page\Shop\Account\LoginPageInterface;
19
use Sylius\Behat\Page\Shop\Account\RegisterPageInterface;
20
use Sylius\Behat\Page\Shop\Account\ResetPasswordPageInterface;
21
use Sylius\Behat\Page\Shop\HomePageInterface;
22
use Sylius\Behat\Service\NotificationCheckerInterface;
23
use Webmozart\Assert\Assert;
24
25
final class LoginContext implements Context
26
{
27
    /**
28
     * @var HomePageInterface
29
     */
30
    private $homePage;
31
32
    /**
33
     * @var LoginPageInterface
34
     */
35
    private $loginPage;
36
37
    /**
38
     * @var RegisterPageInterface
39
     */
40
    private $registerPage;
41
42
    /**
43
     * @var ResetPasswordPageInterface
44
     */
45
    private $resetPasswordPage;
46
47
    /**
48
     * @var NotificationCheckerInterface
49
     */
50
    private $notificationChecker;
51
52
    /**
53
     * @param HomePageInterface $homePage
54
     * @param LoginPageInterface $loginPage
55
     * @param RegisterPageInterface $registerPage
56
     * @param ResetPasswordPageInterface $resetPasswordPage
57
     * @param NotificationCheckerInterface $notificationChecker
58
     */
59
    public function __construct(
60
        HomePageInterface $homePage,
61
        LoginPageInterface $loginPage,
62
        RegisterPageInterface $registerPage,
63
        ResetPasswordPageInterface $resetPasswordPage,
64
        NotificationCheckerInterface $notificationChecker
65
    ) {
66
        $this->homePage = $homePage;
67
        $this->loginPage = $loginPage;
68
        $this->registerPage = $registerPage;
69
        $this->resetPasswordPage = $resetPasswordPage;
70
        $this->notificationChecker = $notificationChecker;
71
    }
72
73
    /**
74
     * @When I want to log in
75
     */
76
    public function iWantToLogIn()
77
    {
78
        $this->loginPage->open();
79
    }
80
81
    /**
82
     * @When I want to reset password
83
     */
84
    public function iWantToResetPassword()
85
    {
86
        $this->resetPasswordPage->open();
87
    }
88
89
    /**
90
     * @When I specify the username as :username
91
     */
92
    public function iSpecifyTheUsername($username = null)
93
    {
94
        $this->loginPage->specifyUsername($username);
95
    }
96
97
    /**
98
     * @When I specify the email as :email
99
     * @When I do not specify the email
100
     */
101
    public function iSpecifyTheEmail($email = null)
102
    {
103
        $this->resetPasswordPage->specifyEmail($email);
104
    }
105
106
    /**
107
     * @When I specify the password as :password
108
     * @When I do not specify the password
109
     */
110
    public function iSpecifyThePasswordAs($password = null)
111
    {
112
        $this->loginPage->specifyPassword($password);
113
    }
114
115
    /**
116
     * @When I log in
117
     * @When I try to log in
118
     */
119
    public function iLogIn()
120
    {
121
        $this->loginPage->logIn();
122
    }
123
124
    /**
125
     * @When I reset it
126
     * @When I try to reset it
127
     */
128
    public function iResetIt()
129
    {
130
        $this->resetPasswordPage->reset();
131
    }
132
133
    /**
134
     * @When I sign in with email :email and password :password
135
     */
136
    public function iSignInWithEmailAndPassword(string $email, string $password): void
137
    {
138
        $this->iWantToLogIn();
139
        $this->iSpecifyTheUsername($email);
140
        $this->iSpecifyThePasswordAs($password);
141
        $this->iLogIn();
142
    }
143
144
    /**
145
     * @When I register with email :email and password :password
146
     */
147
    public function iRegisterWithEmailAndPassword($email, $password)
148
    {
149
        $this->registerPage->open();
150
        $this->registerPage->specifyEmail($email);
151
        $this->registerPage->specifyPassword($password);
152
        $this->registerPage->verifyPassword($password);
153
        $this->registerPage->specifyFirstName('Carrot');
154
        $this->registerPage->specifyLastName('Ironfoundersson');
155
        $this->registerPage->register();
156
    }
157
158
    /**
159
     * @Then I should be logged in
160
     */
161
    public function iShouldBeLoggedIn()
162
    {
163
        $this->homePage->verify();
164
        Assert::true($this->homePage->hasLogoutButton());
165
    }
166
167
    /**
168
     * @Then I should not be logged in
169
     */
170
    public function iShouldNotBeLoggedIn()
171
    {
172
        Assert::false($this->homePage->hasLogoutButton());
173
    }
174
175
    /**
176
     * @Then I should be notified about bad credentials
177
     */
178
    public function iShouldBeNotifiedAboutBadCredentials()
179
    {
180
        Assert::true($this->loginPage->hasValidationErrorWith('Error Invalid credentials.'));
181
    }
182
183
    /**
184
     * @Then I should be notified about disabled account
185
     */
186
    public function iShouldBeNotifiedAboutDisabledAccount()
187
    {
188
        Assert::true($this->loginPage->hasValidationErrorWith('Error Account is disabled.'));
189
    }
190
191
    /**
192
     * @Then I should be notified that email with reset instruction has been sent
193
     */
194
    public function iShouldBeNotifiedThatEmailWithResetInstructionWasSent()
195
    {
196
        $this->notificationChecker->checkNotification('If the email you have specified exists in our system, we have sent there an instruction on how to reset your password.', NotificationType::success());
197
    }
198
199
    /**
200
     * @Then I should be notified that the :elementName is required
201
     */
202
    public function iShouldBeNotifiedThatElementIsRequired($elementName)
203
    {
204
        Assert::true($this->resetPasswordPage->checkValidationMessageFor($elementName, sprintf('Please enter your %s.', $elementName)));
205
    }
206
207
    /**
208
     * @Then I should be able to log in as :email with :password password
209
     * @Then the customer should be able to log in as :email with :password password
210
     */
211
    public function iShouldBeAbleToLogInAsWithPassword($email, $password)
212
    {
213
        $this->loginPage->open();
214
        $this->loginPage->specifyUsername($email);
215
        $this->loginPage->specifyPassword($password);
216
        $this->loginPage->logIn();
217
218
        $this->iShouldBeLoggedIn();
219
    }
220
}
221