11
11
use Magento \Customer \Api \Data \CustomerInterface ;
12
12
use Magento \Customer \Model \CustomerRegistry ;
13
13
use Magento \Framework \App \Http ;
14
+ use Magento \Framework \App \Request \Http as HttpRequest ;
14
15
use Magento \Framework \Exception \NoSuchEntityException ;
15
16
use Magento \Framework \Message \MessageInterface ;
16
17
use Magento \Framework \Stdlib \CookieManagerInterface ;
18
+ use Magento \Framework \UrlInterface ;
17
19
use Magento \Store \Model \StoreManagerInterface ;
18
20
use Magento \TestFramework \Mail \Template \TransportBuilderMock ;
19
21
use Magento \TestFramework \Request ;
20
22
use Magento \TestFramework \TestCase \AbstractController ;
21
23
use Magento \Theme \Controller \Result \MessagePlugin ;
22
24
23
25
/**
26
+ * Tests from customer account create post action.
27
+ *
24
28
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
25
29
*/
26
30
class CreatePostTest extends AbstractController
@@ -50,6 +54,11 @@ class CreatePostTest extends AbstractController
50
54
*/
51
55
private $ cookieManager ;
52
56
57
+ /**
58
+ * @var UrlInterface
59
+ */
60
+ private $ urlBuilder ;
61
+
53
62
/**
54
63
* @inheritdoc
55
64
*/
@@ -62,6 +71,7 @@ protected function setUp()
62
71
$ this ->customerRepository = $ this ->_objectManager ->get (CustomerRepositoryInterface::class);
63
72
$ this ->customerRegistry = $ this ->_objectManager ->get (CustomerRegistry::class);
64
73
$ this ->cookieManager = $ this ->_objectManager ->get (CookieManagerInterface::class);
74
+ $ this ->urlBuilder = $ this ->_objectManager ->get (UrlInterface::class);
65
75
}
66
76
67
77
/**
@@ -81,7 +91,7 @@ public function testNoFormKeyCreatePostAction(): void
81
91
$ this ->assertCustomerNotExists ('test1@email.com ' );
82
92
$ this ->assertRedirect ($ this ->stringEndsWith ('customer/account/create/ ' ));
83
93
$ this ->assertSessionMessages (
84
- $ this ->equalTo ([ __ ('Invalid Form Key. Please refresh the page. ' )] ),
94
+ $ this ->contains ( __ ('Invalid Form Key. Please refresh the page. ' )),
85
95
MessageInterface::TYPE_ERROR
86
96
);
87
97
}
@@ -101,7 +111,9 @@ public function testNoConfirmCreatePostAction(): void
101
111
$ this ->dispatch ('customer/account/createPost ' );
102
112
$ this ->assertRedirect ($ this ->stringEndsWith ('customer/account/ ' ));
103
113
$ this ->assertSessionMessages (
104
- $ this ->equalTo ([__ ('Thank you for registering with Main Website Store. ' )]),
114
+ $ this ->contains (
115
+ (string )__ ('Thank you for registering with %1. ' , $ this ->storeManager ->getStore ()->getFrontendName ())
116
+ ),
105
117
MessageInterface::TYPE_SUCCESS
106
118
);
107
119
$ customer = $ this ->customerRegistry ->retrieveByEmail ('test1@email.com ' );
@@ -125,7 +137,9 @@ public function testCreatePostWithCustomConfiguration(): void
125
137
$ this ->dispatch ('customer/account/createPost ' );
126
138
$ this ->assertRedirect ($ this ->stringEndsWith ('customer/account/ ' ));
127
139
$ this ->assertSessionMessages (
128
- $ this ->equalTo ([__ ('Thank you for registering with Main Website Store. ' )]),
140
+ $ this ->contains (
141
+ (string )__ ('Thank you for registering with %1. ' , $ this ->storeManager ->getStore ()->getFrontendName ())
142
+ ),
129
143
MessageInterface::TYPE_SUCCESS
130
144
);
131
145
$ customer = $ this ->customerRegistry ->retrieveByEmail ('test@email.com ' );
@@ -145,13 +159,17 @@ public function testCreatePostWithCustomConfiguration(): void
145
159
*/
146
160
public function testWithConfirmCreatePostAction (): void
147
161
{
148
- $ this ->fillRequestWithAccountData ('test2@email.com ' );
162
+ $ email = 'test2@email.com ' ;
163
+ $ this ->fillRequestWithAccountData ($ email );
149
164
$ this ->dispatch ('customer/account/createPost ' );
150
165
$ this ->assertRedirect ($ this ->stringContains ('customer/account/index/ ' ));
151
166
$ message = 'You must confirm your account. '
152
167
. ' Please check your email for the confirmation link or <a href="%1">click here</a> for a new link. ' ;
153
- $ url = 'http://localhost/index.php/customer/account/confirmation/?email=test2%40email.com ' ;
154
- $ this ->assertSessionMessages ($ this ->equalTo ([__ ($ message , $ url )]), MessageInterface::TYPE_SUCCESS );
168
+ $ url = $ this ->urlBuilder ->getUrl ('customer/account/confirmation ' , ['_query ' => ['email ' => $ email ]]);
169
+ $ this ->assertSessionMessages (
170
+ $ this ->contains ((string )__ ($ message , $ url )),
171
+ MessageInterface::TYPE_SUCCESS
172
+ );
155
173
}
156
174
157
175
/**
@@ -167,8 +185,8 @@ public function testExistingEmailCreatePostAction(): void
167
185
$ message = 'There is already an account with this email address. '
168
186
. ' If you are sure that it is your email address, <a href="%1">click here</a> '
169
187
. 'to get your password and access your account. ' ;
170
- $ url = ' http://localhost/index.php/ customer/account/forgotpassword/ ' ;
171
- $ this ->assertSessionMessages ($ this ->equalTo ([ (string )__ ($ message , $ url )] ), MessageInterface::TYPE_ERROR );
188
+ $ url = $ this -> urlBuilder -> getUrl ( ' customer/account/forgotpassword ' ) ;
189
+ $ this ->assertSessionMessages ($ this ->contains ( (string )__ ($ message , $ url )), MessageInterface::TYPE_ERROR );
172
190
}
173
191
174
192
/**
@@ -186,12 +204,14 @@ public function testRegisterCustomerWithEmailConfirmation(): void
186
204
$ this ->assertRedirect ($ this ->stringContains ('customer/account/index/ ' ));
187
205
$ message = 'You must confirm your account. '
188
206
. ' Please check your email for the confirmation link or <a href="%1">click here</a> for a new link. ' ;
189
- $ url = ' http://localhost/index.php/ customer/account/confirmation/?email=test_example%40email.com ' ;
207
+ $ url = $ this -> urlBuilder -> getUrl ( ' customer/account/confirmation ' , [ ' _query ' => [ ' email ' => $ email ]]) ;
190
208
$ this ->assertSessionMessages ($ this ->equalTo ([(string )__ ($ message , $ url )]), MessageInterface::TYPE_SUCCESS );
191
209
/** @var CustomerInterface $customer */
192
210
$ customer = $ this ->customerRepository ->get ($ email );
193
211
$ confirmation = $ customer ->getConfirmation ();
194
- $ rawMessage = $ this ->transportBuilderMock ->getSentMessage ()->getBody ()->getParts ()[0 ]->getRawContent ();
212
+ $ sendMessage = $ this ->transportBuilderMock ->getSentMessage ();
213
+ $ this ->assertNotNull ($ sendMessage );
214
+ $ rawMessage = $ sendMessage ->getBody ()->getParts ()[0 ]->getRawContent ();
195
215
$ this ->assertContains (
196
216
(string )__ (
197
217
'You must confirm your %customer_email email before you can sign in (link is only valid once): ' ,
@@ -210,8 +230,8 @@ public function testRegisterCustomerWithEmailConfirmation(): void
210
230
$ this ->dispatch ('customer/account/confirm ' );
211
231
$ this ->assertRedirect ($ this ->stringContains ('customer/account/index/ ' ));
212
232
$ this ->assertSessionMessages (
213
- $ this ->equalTo (
214
- [ __ ('Thank you for registering with %1. ' , $ this ->storeManager ->getStore ()->getFrontendName ())]
233
+ $ this ->contains (
234
+ ( string ) __ ('Thank you for registering with %1. ' , $ this ->storeManager ->getStore ()->getFrontendName ())
215
235
),
216
236
MessageInterface::TYPE_SUCCESS
217
237
);
@@ -224,10 +244,10 @@ public function testRegisterCustomerWithEmailConfirmation(): void
224
244
* @param string $email
225
245
* @return void
226
246
*/
227
- private function fillRequestWithAccountData ($ email ): void
247
+ private function fillRequestWithAccountData (string $ email ): void
228
248
{
229
249
$ this ->getRequest ()
230
- ->setMethod (' POST ' )
250
+ ->setMethod (HttpRequest:: METHOD_POST )
231
251
->setParam (CustomerInterface::FIRSTNAME , 'firstname1 ' )
232
252
->setParam (CustomerInterface::LASTNAME , 'lastname1 ' )
233
253
->setParam (CustomerInterface::EMAIL , $ email )
0 commit comments