|
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\Api\Shop; |
|
15
|
|
|
|
|
16
|
|
|
use Behat\Behat\Context\Context; |
|
17
|
|
|
use Symfony\Component\BrowserKit\AbstractBrowser; |
|
18
|
|
|
use Webmozart\Assert\Assert; |
|
19
|
|
|
|
|
20
|
|
|
final class RegistrationContext implements Context |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var AbstractBrowser */ |
|
23
|
|
|
private $client; |
|
24
|
|
|
|
|
25
|
|
|
private $content = []; |
|
26
|
|
|
|
|
27
|
|
|
public function __construct(AbstractBrowser $client) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->client = $client; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @When I want to register a new account |
|
34
|
|
|
* @When I want to again register a new account |
|
35
|
|
|
*/ |
|
36
|
|
|
public function iWantToRegisterNewAccount(): void |
|
37
|
|
|
{ |
|
38
|
|
|
$this->content = [ |
|
39
|
|
|
'firstName' => 'First', |
|
40
|
|
|
'lastName' => 'Last', |
|
41
|
|
|
'email' => '[email protected]', |
|
42
|
|
|
'password' => 'example', |
|
43
|
|
|
]; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @When I specify the first name as :firstName |
|
48
|
|
|
* @When I do not specify the first name |
|
49
|
|
|
*/ |
|
50
|
|
|
public function iSpecifyTheFirstNameAs(string $firstName = ''): void |
|
51
|
|
|
{ |
|
52
|
|
|
$this->content['firstName'] = $firstName; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @When I specify the last name as :lastName |
|
57
|
|
|
* @When I do not specify the last name |
|
58
|
|
|
*/ |
|
59
|
|
|
public function iSpecifyTheLastNameAs(string $lastName = ''): void |
|
60
|
|
|
{ |
|
61
|
|
|
$this->content['lastName'] = $lastName; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @When I specify the email as :email |
|
66
|
|
|
* @When I do not specify the email |
|
67
|
|
|
*/ |
|
68
|
|
|
public function iSpecifyTheEmailAs(string $email = ''): void |
|
69
|
|
|
{ |
|
70
|
|
|
$this->content['email'] = $email; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @When I specify the password as :password |
|
75
|
|
|
* @When I do not specify the password |
|
76
|
|
|
*/ |
|
77
|
|
|
public function iSpecifyThePasswordAs(string $password = ''): void |
|
78
|
|
|
{ |
|
79
|
|
|
$this->content['password'] = $password; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @When I specify the phone number as :phoneNumber |
|
84
|
|
|
*/ |
|
85
|
|
|
public function iSpecifyThePhoneNumberAs(string $phoneNumber): void |
|
86
|
|
|
{ |
|
87
|
|
|
$this->content['phoneNumber'] = $phoneNumber; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @When I confirm this password |
|
92
|
|
|
*/ |
|
93
|
|
|
public function iConfirmThisPassword(): void |
|
94
|
|
|
{ |
|
95
|
|
|
// Intentionally left blank |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @When I register this account |
|
100
|
|
|
* @When I try to register this account |
|
101
|
|
|
*/ |
|
102
|
|
|
public function iRegisterThisAccount(): void |
|
103
|
|
|
{ |
|
104
|
|
|
$this->client->request( |
|
105
|
|
|
'POST', |
|
106
|
|
|
'/new-api/register', |
|
107
|
|
|
[], |
|
108
|
|
|
[], |
|
109
|
|
|
['HTTP_ACCEPT' => 'application/ld+json', 'CONTENT_TYPE' => 'application/ld+json'], |
|
110
|
|
|
json_encode($this->content, \JSON_THROW_ON_ERROR) |
|
111
|
|
|
); |
|
112
|
|
|
$this->content = []; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @Then I should be notified that new account has been successfully created |
|
117
|
|
|
*/ |
|
118
|
|
|
public function iShouldBeNotifiedThatNewAccountHasBeenSuccessfullyCreated(): void |
|
119
|
|
|
{ |
|
120
|
|
|
Assert::same($this->client->getResponse()->getStatusCode(), 204); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @Then I should be notified that the first name is required |
|
125
|
|
|
*/ |
|
126
|
|
|
public function iShouldBeNotifiedThatTheFirstNameIsRequired(): void |
|
127
|
|
|
{ |
|
128
|
|
|
$this->assertFieldValidationMessage('firstName', 'Please enter your first name.'); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @Then I should be notified that the last name is required |
|
133
|
|
|
*/ |
|
134
|
|
|
public function iShouldBeNotifiedThatTheLastNameIsRequired(): void |
|
135
|
|
|
{ |
|
136
|
|
|
$this->assertFieldValidationMessage('lastName', 'Please enter your last name.'); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @Then I should be notified that the password is required |
|
141
|
|
|
*/ |
|
142
|
|
|
public function iShouldBeNotifiedThatThePasswordIsRequired(): void |
|
143
|
|
|
{ |
|
144
|
|
|
$this->assertFieldValidationMessage('password', 'Please enter your password.'); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @Then I should be notified that the email is required |
|
149
|
|
|
*/ |
|
150
|
|
|
public function iShouldBeNotifiedThatTheEmailIsRequired(): void |
|
151
|
|
|
{ |
|
152
|
|
|
$this->assertFieldValidationMessage('email', 'Please enter your email.'); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @Then I should be notified that the email is already used |
|
157
|
|
|
*/ |
|
158
|
|
|
public function iShouldBeNotifiedThatTheEmailIsAlreadyUsed(): void |
|
159
|
|
|
{ |
|
160
|
|
|
$this->assertFieldValidationMessage('email', 'This email is already used.'); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @Then I should not be logged in |
|
165
|
|
|
*/ |
|
166
|
|
|
public function iShouldNotBeLoggedIn(): void |
|
167
|
|
|
{ |
|
168
|
|
|
// Intentionally left blank |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @Then I should be logged in |
|
173
|
|
|
*/ |
|
174
|
|
|
public function iShouldBeLoggedIn(): void |
|
175
|
|
|
{ |
|
176
|
|
|
// Intentionally left blank |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
private function assertFieldValidationMessage(string $path, string $message): void |
|
180
|
|
|
{ |
|
181
|
|
|
$decodedResponse = json_decode($this->client->getResponse()->getContent(), true, 512, \JSON_THROW_ON_ERROR); |
|
182
|
|
|
|
|
183
|
|
|
Assert::keyExists($decodedResponse, 'violations'); |
|
184
|
|
|
Assert::oneOf( |
|
185
|
|
|
['propertyPath' => $path, 'message' => $message], |
|
186
|
|
|
$decodedResponse['violations'] |
|
187
|
|
|
); |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
|