Completed
Push — example/managing-articles ( a73081...648917 )
by Loïc
05:32 queued 03:08
created

AccountContext::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 5
1
<?php
2
3
/*
4
 * This file is part of AppName.
5
 *
6
 * (c) Monofony
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 App\Behat\Context\Ui\Frontend;
15
16
use Behat\Behat\Context\Context;
17
use App\Behat\NotificationType;
18
use App\Behat\Page\Frontend\Account\ChangePasswordPage;
19
use App\Behat\Page\Frontend\Account\DashboardPage;
20
use App\Behat\Page\Frontend\Account\LoginPage;
21
use App\Behat\Page\Frontend\Account\ProfileUpdatePage;
22
use App\Behat\Service\NotificationCheckerInterface;
23
use App\Formatter\StringInflector;
24
use Webmozart\Assert\Assert;
25
26
final class AccountContext implements Context
27
{
28
    /**
29
     * @var DashboardPage
30
     */
31
    private $dashboardPage;
32
33
    /**
34
     * @var ProfileUpdatePage
35
     */
36
    private $profileUpdatePage;
37
38
    /**
39
     * @var ChangePasswordPage
40
     */
41
    private $changePasswordPage;
42
43
    /**
44
     * @var LoginPage
45
     */
46
    private $loginPage;
47
48
    /**
49
     * @var NotificationCheckerInterface
50
     */
51
    private $notificationChecker;
52
53
    /**
54
     * @param DashboardPage                $dashboardPage
55
     * @param ProfileUpdatePage            $profileUpdatePage
56
     * @param ChangePasswordPage           $changePasswordPage
57
     * @param LoginPage                    $loginPage
58
     * @param NotificationCheckerInterface $notificationChecker
59
     */
60
    public function __construct(
61
        DashboardPage $dashboardPage,
62
        ProfileUpdatePage $profileUpdatePage,
63
        ChangePasswordPage $changePasswordPage,
64
        LoginPage $loginPage,
65
        NotificationCheckerInterface $notificationChecker
66
    ) {
67
        $this->dashboardPage = $dashboardPage;
68
        $this->profileUpdatePage = $profileUpdatePage;
69
        $this->changePasswordPage = $changePasswordPage;
70
        $this->loginPage = $loginPage;
71
        $this->notificationChecker = $notificationChecker;
72
    }
73
74
    /**
75
     * @When I want to modify my profile
76
     */
77
    public function iWantToModifyMyProfile()
78
    {
79
        $this->profileUpdatePage->open();
80
    }
81
82
    /**
83
     * @When I specify the first name as :firstName
84
     * @When I remove the first name
85
     */
86
    public function iSpecifyTheFirstName($firstName = null)
87
    {
88
        $this->profileUpdatePage->specifyFirstName($firstName);
89
    }
90
91
    /**
92
     * @When I specify the last name as :lastName
93
     * @When I remove the last name
94
     */
95
    public function iSpecifyTheLastName($lastName = null)
96
    {
97
        $this->profileUpdatePage->specifyLastName($lastName);
98
    }
99
100
    /**
101
     * @When I specify the customer email as :email
102
     * @When I remove the customer email
103
     */
104
    public function iSpecifyCustomerTheEmail($email = null)
105
    {
106
        $this->profileUpdatePage->specifyEmail($email);
107
    }
108
109
    /**
110
     * @When I save my changes
111
     * @When I try to save my changes
112
     */
113
    public function iSaveMyChanges()
114
    {
115
        $this->profileUpdatePage->saveChanges();
116
    }
117
118
    /**
119
     * @Then I should be notified that it has been successfully edited
120
     */
121
    public function iShouldBeNotifiedThatItHasBeenSuccessfullyEdited()
122
    {
123
        $this->notificationChecker->checkNotification('has been successfully updated.', NotificationType::success());
124
    }
125
126
    /**
127
     * @Then my name should be :name
128
     * @Then my name should still be :name
129
     */
130
    public function myNameShouldBe($name)
131
    {
132
        $this->dashboardPage->open();
133
134
        Assert::true($this->dashboardPage->hasCustomerName($name));
135
    }
136
137
    /**
138
     * @Then my email should be :email
139
     * @Then my email should still be :email
140
     */
141
    public function myEmailShouldBe($email)
142
    {
143
        $this->dashboardPage->open();
144
145
        Assert::true($this->dashboardPage->hasCustomerEmail($email));
146
    }
147
148
    /**
149
     * @Then /^I should be notified that the (email|password|city|street|first name|last name) is required$/
150
     */
151
    public function iShouldBeNotifiedThatElementIsRequired($element)
152
    {
153
        Assert::true($this->profileUpdatePage->checkValidationMessageFor(
154
            StringInflector::nameToCode($element),
155
            sprintf('Please enter your %s.', $element)
156
        ));
157
    }
158
159
    /**
160
     * @Then /^I should be notified that the (email) is invalid$/
161
     */
162
    public function iShouldBeNotifiedThatElementIsInvalid($element)
163
    {
164
        Assert::true($this->profileUpdatePage->checkValidationMessageFor(
165
            StringInflector::nameToCode($element),
166
            sprintf('This %s is invalid.', $element)
167
        ));
168
    }
169
170
    /**
171
     * @Then I should be notified that the email is already used
172
     */
173
    public function iShouldBeNotifiedThatTheEmailIsAlreadyUsed()
174
    {
175
        Assert::true($this->profileUpdatePage->checkValidationMessageFor('email', 'This email is already used.'));
176
    }
177
178
    /**
179
     * @Given /^I want to change my password$/
180
     */
181
    public function iWantToChangeMyPassword()
182
    {
183
        $this->changePasswordPage->open();
184
    }
185
186
    /**
187
     * @Given I change password from :oldPassword to :newPassword
188
     */
189
    public function iChangePasswordTo($oldPassword, $newPassword)
190
    {
191
        $this->iSpecifyTheCurrentPasswordAs($oldPassword);
192
        $this->iSpecifyTheNewPasswordAs($newPassword);
193
        $this->iSpecifyTheConfirmationPasswordAs($newPassword);
194
    }
195
196
    /**
197
     * @Then I should be notified that my password has been successfully changed
198
     */
199
    public function iShouldBeNotifiedThatMyPasswordHasBeenSuccessfullyChanged()
200
    {
201
        $this->notificationChecker->checkNotification('has been changed successfully!', NotificationType::success());
202
    }
203
204
    /**
205
     * @Given I specify the current password as :password
206
     */
207
    public function iSpecifyTheCurrentPasswordAs($password)
208
    {
209
        $this->changePasswordPage->specifyCurrentPassword($password);
210
    }
211
212
    /**
213
     * @Given I specify the new password as :password
214
     */
215
    public function iSpecifyTheNewPasswordAs($password)
216
    {
217
        $this->changePasswordPage->specifyNewPassword($password);
218
    }
219
220
    /**
221
     * @Given I confirm this password as :password
222
     */
223
    public function iSpecifyTheConfirmationPasswordAs($password)
224
    {
225
        $this->changePasswordPage->specifyConfirmationPassword($password);
226
    }
227
228
    /**
229
     * @Then I should be notified that provided password is different than the current one
230
     */
231
    public function iShouldBeNotifiedThatProvidedPasswordIsDifferentThanTheCurrentOne()
232
    {
233
        Assert::true($this->changePasswordPage->checkValidationMessageFor(
234
            'current_password',
235
            'Provided password is different than the current one.'
236
        ));
237
    }
238
239
    /**
240
     * @Then I should be notified that the entered passwords do not match
241
     */
242
    public function iShouldBeNotifiedThatTheEnteredPasswordsDoNotMatch()
243
    {
244
        Assert::true($this->changePasswordPage->checkValidationMessageFor(
245
            'new_password',
246
            'The entered passwords don\'t match'
247
        ));
248
    }
249
250
    /**
251
     * @Then I should be notified that the password should be at least 4 characters long
252
     */
253
    public function iShouldBeNotifiedThatThePasswordShouldBeAtLeastCharactersLong()
254
    {
255
        Assert::true($this->changePasswordPage->checkValidationMessageFor(
256
            'new_password',
257
            'Password must be at least 4 characters long.'
258
        ));
259
    }
260
261
    /**
262
     * @When I subscribe to the newsletter
263
     */
264
    public function iSubscribeToTheNewsletter()
265
    {
266
        $this->profileUpdatePage->subscribeToTheNewsletter();
267
    }
268
269
    /**
270
     * @Then I should be subscribed to the newsletter
271
     */
272
    public function iShouldBeSubscribedToTheNewsletter()
273
    {
274
        Assert::true($this->profileUpdatePage->isSubscribedToTheNewsletter());
275
    }
276
277
    /**
278
     * @Then I should be redirected to my account dashboard
279
     */
280
    public function iShouldBeRedirectedToMyAccountDashboard()
281
    {
282
        Assert::true($this->dashboardPage->isOpen(), 'User should be on the account panel dashboard page but they are not.');
283
    }
284
285
    /**
286
     * @When I want to log in
287
     */
288
    public function iWantToLogIn()
289
    {
290
        $this->loginPage->tryToOpen();
291
    }
292
}
293