Completed
Push — utc-datetime-storing ( 6fbf75...e1fcef )
by Kamil
25:51
created

iChangeItsPasswordAs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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\Admin;
15
16
use Behat\Behat\Context\Context;
17
use Sylius\Behat\NotificationType;
18
use Sylius\Behat\Page\Admin\Administrator\CreatePageInterface;
19
use Sylius\Behat\Page\Admin\Administrator\UpdatePageInterface;
20
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface;
21
use Sylius\Behat\Service\NotificationCheckerInterface;
22
use Sylius\Component\Core\Model\AdminUserInterface;
23
use Webmozart\Assert\Assert;
24
25
/**
26
 * @author Arkadiusz Krakowiak <[email protected]>
27
 */
28
final class ManagingAdministratorsContext implements Context
29
{
30
    /**
31
     * @var CreatePageInterface
32
     */
33
    private $createPage;
34
35
    /**
36
     * @var IndexPageInterface
37
     */
38
    private $indexPage;
39
40
    /**
41
     * @var UpdatePageInterface
42
     */
43
    private $updatePage;
44
45
    /**
46
     * @var NotificationCheckerInterface
47
     */
48
    private $notificationChecker;
49
50
    /**
51
     * @param CreatePageInterface $createPage
52
     * @param IndexPageInterface $indexPage
53
     * @param UpdatePageInterface $updatePage
54
     * @param NotificationCheckerInterface $notificationChecker
55
     */
56
    public function __construct(
57
        CreatePageInterface $createPage,
58
        IndexPageInterface $indexPage,
59
        UpdatePageInterface $updatePage,
60
        NotificationCheckerInterface $notificationChecker
61
    ) {
62
        $this->createPage = $createPage;
63
        $this->indexPage = $indexPage;
64
        $this->updatePage = $updatePage;
65
        $this->notificationChecker = $notificationChecker;
66
    }
67
68
    /**
69
     * @Given I want to create a new administrator
70
     */
71
    public function iWantToCreateANewAdministrator()
72
    {
73
        $this->createPage->open();
74
    }
75
76
    /**
77
     * @Given /^I am editing (my) details$/
78
     * @When /^I want to edit (this administrator)$/
79
     */
80
    public function iWantToEditThisAdministrator(AdminUserInterface $adminUser)
81
    {
82
        $this->updatePage->open(['id' => $adminUser->getId()]);
83
    }
84
85
    /**
86
     * @When I want to browse administrators
87
     */
88
    public function iWantToBrowseAdministrators()
89
    {
90
        $this->indexPage->open();
91
    }
92
93
    /**
94
     * @When I specify its name as :username
95
     * @When I do not specify its name
96
     */
97
    public function iSpecifyItsNameAs($username = null)
98
    {
99
        $this->createPage->specifyUsername($username);
100
    }
101
102
    /**
103
     * @When I change its name to :username
104
     */
105
    public function iChangeItsNameTo($username)
106
    {
107
        $this->updatePage->changeUsername($username);
108
    }
109
110
    /**
111
     * @When I specify its email as :email
112
     * @When I do not specify its email
113
     */
114
    public function iSpecifyItsEmailAs($email = null)
115
    {
116
        $this->createPage->specifyEmail($email);
117
    }
118
119
    /**
120
     * @When I change its email to :email
121
     */
122
    public function iChangeItsEmailTo($email)
123
    {
124
        $this->updatePage->changeEmail($email);
125
    }
126
127
    /**
128
     * @When I specify its locale as :localeCode
129
     */
130
    public function iSpecifyItsLocaleAs($localeCode)
131
    {
132
        $this->createPage->specifyLocale($localeCode);
133
    }
134
135
    /**
136
     * @When I set my locale to :localeCode
137
     */
138
    public function iSetMyLocaleTo($localeCode)
139
    {
140
        $this->updatePage->changeLocale($localeCode);
141
        $this->updatePage->saveChanges();
142
    }
143
144
    /**
145
     * @When I specify its password as :password
146
     * @When I do not specify its password
147
     */
148
    public function iSpecifyItsPasswordAs($password = null)
149
    {
150
        $this->createPage->specifyPassword($password);
151
    }
152
153
    /**
154
     * @When I change its password to :password
155
     */
156
    public function iChangeItsPasswordTo($password)
157
    {
158
        $this->updatePage->changePassword($password);
159
    }
160
161
    /**
162
     * @When I enable it
163
     */
164
    public function iEnableIt()
165
    {
166
        $this->createPage->enable();
167
    }
168
169
    /**
170
     * @When I add it
171
     * @When I try to add it
172
     */
173
    public function iAddIt()
174
    {
175
        $this->createPage->create();
176
    }
177
178
    /**
179
     * @When I save my changes
180
     */
181
    public function iSaveMyChanges()
182
    {
183
        $this->updatePage->saveChanges();
184
    }
185
186
    /**
187
     * @When I delete administrator with email :email
188
     */
189
    public function iDeleteAdministratorWithEmail($email)
190
    {
191
        $this->indexPage->deleteResourceOnPage(['email' => $email]);
192
    }
193
194
    /**
195
     * @Then the administrator :email should appear in the store
196
     * @Then I should see the administrator :email in the list
197
     * @Then there should still be only one administrator with an email :email
198
     */
199
    public function theAdministratorShouldAppearInTheStore($email)
200
    {
201
        $this->indexPage->open();
202
203
        Assert::true($this->indexPage->isSingleResourceOnPage(['email' => $email]));
204
    }
205
206
    /**
207
     * @Then this administrator with name :username should appear in the store
208
     * @Then there should still be only one administrator with name :username
209
     */
210
    public function thisAdministratorWithNameShouldAppearInTheStore($username)
211
    {
212
        $this->indexPage->open();
213
214
        Assert::true($this->indexPage->isSingleResourceOnPage(['username' => $username]));
215
    }
216
217
    /**
218
     * @Then /^there should be (\d+) administrators in the list$/
219
     */
220
    public function iShouldSeeAdministratorsInTheList($number)
221
    {
222
        Assert::same($this->indexPage->countItems(), (int) $number);
223
    }
224
225
    /**
226
     * @Then I should be notified that email must be unique
227
     */
228
    public function iShouldBeNotifiedThatEmailMustBeUnique()
229
    {
230
        Assert::same($this->createPage->getValidationMessage('email'), 'This email is already used.');
231
    }
232
233
    /**
234
     * @Then I should be notified that name must be unique
235
     */
236
    public function iShouldBeNotifiedThatNameMustBeUnique()
237
    {
238
        Assert::same($this->createPage->getValidationMessage('name'), 'This username is already used.');
239
    }
240
241
    /**
242
     * @Then I should be notified that the :elementName is required
243
     */
244
    public function iShouldBeNotifiedThatFirstNameIsRequired($elementName)
245
    {
246
        Assert::same($this->createPage->getValidationMessage($elementName), sprintf('Please enter your %s.', $elementName));
247
    }
248
249
    /**
250
     * @Then I should be notified that this email is not valid
251
     */
252
    public function iShouldBeNotifiedThatEmailIsNotValid()
253
    {
254
        Assert::same($this->createPage->getValidationMessage('email'), 'This email is invalid.');
255
    }
256
257
    /**
258
     * @Then this administrator should not be added
259
     */
260
    public function thisAdministratorShouldNotBeAdded()
261
    {
262
        $this->indexPage->open();
263
264
        Assert::same($this->indexPage->countItems(), 1);
265
    }
266
267
    /**
268
     * @Then there should not be :email administrator anymore
269
     */
270
    public function thereShouldBeNoAnymore($email)
271
    {
272
        Assert::false($this->indexPage->isSingleResourceOnPage(['email' => $email]));
273
    }
274
275
    /**
276
     * @Then I should be notified that it cannot be deleted
277
     */
278
    public function iShouldBeNotifiedThatItCannotBeDeleted()
279
    {
280
        $this->notificationChecker->checkNotification(
281
            'Cannot remove currently logged in user.',
282
            NotificationType::failure()
283
        );
284
    }
285
}
286