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
|
|
|
namespace Sylius\Behat\Context\Ui\Shop; |
13
|
|
|
|
14
|
|
|
use Behat\Behat\Context\Context; |
15
|
|
|
use Sylius\Behat\NotificationType; |
16
|
|
|
use Sylius\Behat\Page\Shop\Account\DashboardPage; |
17
|
|
|
use Sylius\Behat\Page\Shop\Account\DashboardPageInterface; |
18
|
|
|
use Sylius\Behat\Page\Shop\Account\ProfileUpdatePageInterface; |
19
|
|
|
use Sylius\Behat\Service\NotificationCheckerInterface; |
20
|
|
|
use Sylius\Component\Core\Test\Services\SharedStorageInterface; |
21
|
|
|
use Webmozart\Assert\Assert; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @author Grzegorz Sadowski <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
final class AccountContext implements Context |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var DashboardPageInterface |
30
|
|
|
*/ |
31
|
|
|
private $dashboardPage; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var ProfileUpdatePageInterface |
35
|
|
|
*/ |
36
|
|
|
private $profileUpdatePage; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var NotificationCheckerInterface |
40
|
|
|
*/ |
41
|
|
|
private $notificationChecker; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param DashboardPageInterface $dashboardPage |
45
|
|
|
* @param ProfileUpdatePageInterface $profileUpdatePage |
46
|
|
|
* @param NotificationCheckerInterface $notificationChecker |
47
|
|
|
*/ |
48
|
|
|
public function __construct( |
49
|
|
|
DashboardPageInterface $dashboardPage, |
50
|
|
|
ProfileUpdatePageInterface $profileUpdatePage, |
51
|
|
|
NotificationCheckerInterface $notificationChecker |
52
|
|
|
) { |
53
|
|
|
$this->dashboardPage = $dashboardPage; |
54
|
|
|
$this->profileUpdatePage = $profileUpdatePage; |
55
|
|
|
$this->notificationChecker = $notificationChecker; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @Given I want to modify my profile |
60
|
|
|
*/ |
61
|
|
|
public function iWantToModifyMyProfile() |
62
|
|
|
{ |
63
|
|
|
$this->profileUpdatePage->open(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @When I specify the first name as :firstName |
68
|
|
|
* @When I remove the first name |
69
|
|
|
*/ |
70
|
|
|
public function iSpecifyTheFirstName($firstName = null) |
71
|
|
|
{ |
72
|
|
|
$this->profileUpdatePage->specifyFirstName($firstName); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @When I specify the last name as :lastName |
77
|
|
|
* @When I remove the last name |
78
|
|
|
*/ |
79
|
|
|
public function iSpecifyTheLastName($lastName = null) |
80
|
|
|
{ |
81
|
|
|
$this->profileUpdatePage->specifyLastName($lastName); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @When I specify the email as :email |
86
|
|
|
* @When I remove the email |
87
|
|
|
*/ |
88
|
|
|
public function iSpecifyTheEmail($email = null) |
89
|
|
|
{ |
90
|
|
|
$this->profileUpdatePage->specifyEmail($email); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @When I save my changes |
95
|
|
|
* @When I try to save my changes |
96
|
|
|
*/ |
97
|
|
|
public function iSaveMyChanges() |
98
|
|
|
{ |
99
|
|
|
$this->profileUpdatePage->saveChanges(); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @Then I should be notified that it has been successfully edited |
104
|
|
|
*/ |
105
|
|
|
public function iShouldBeNotifiedThatItHasBeenSuccessfullyEdited() |
106
|
|
|
{ |
107
|
|
|
$this->notificationChecker->checkNotification('has been successfully updated.', NotificationType::success()); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @Then my name should be :name |
112
|
|
|
* @Then my name should still be :name |
113
|
|
|
*/ |
114
|
|
|
public function myNameShouldBe($name) |
115
|
|
|
{ |
116
|
|
|
$this->dashboardPage->open(); |
117
|
|
|
|
118
|
|
|
Assert::true( |
119
|
|
|
$this->dashboardPage->hasCustomerName($name), |
120
|
|
|
sprintf('Cannot find customer name "%s".', $name) |
121
|
|
|
); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @Then my email should be :email |
126
|
|
|
* @Then my email should still be :email |
127
|
|
|
*/ |
128
|
|
|
public function myEmailShouldBe($email) |
129
|
|
|
{ |
130
|
|
|
$this->dashboardPage->open(); |
131
|
|
|
|
132
|
|
|
Assert::true( |
133
|
|
|
$this->dashboardPage->hasCustomerEmail($email), |
134
|
|
|
sprintf('Cannot find customer email "%s".', $email) |
135
|
|
|
); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @Then /^I should be notified that the ([^"]+) is required$/ |
140
|
|
|
*/ |
141
|
|
|
public function iShouldBeNotifiedThatElementIsRequired($element) |
142
|
|
|
{ |
143
|
|
|
$this->assertFieldValidationMessage($element, sprintf('Please enter your %s.', $element)); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @Then /^I should be notified that the ([^"]+) is invalid$/ |
148
|
|
|
*/ |
149
|
|
|
public function iShouldBeNotifiedThatElementIsInvalid($element) |
150
|
|
|
{ |
151
|
|
|
$this->assertFieldValidationMessage($element, sprintf('This %s is invalid.', $element)); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @Then I should be notified that the email is already used |
156
|
|
|
*/ |
157
|
|
|
public function iShouldBeNotifiedThatTheEmailIsAlreadyUsed() |
158
|
|
|
{ |
159
|
|
|
$this->assertFieldValidationMessage('email', 'This email is already used.'); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @param string $element |
164
|
|
|
* @param string $expectedMessage |
165
|
|
|
*/ |
166
|
|
|
private function assertFieldValidationMessage($element, $expectedMessage) |
167
|
|
|
{ |
168
|
|
|
Assert::true( |
169
|
|
|
$this->profileUpdatePage->checkValidationMessageFor($element, $expectedMessage), |
170
|
|
|
sprintf('The %s should be required.', $element) |
171
|
|
|
); |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|