17
17
use Magento \Framework \App \Http ;
18
18
use Magento \Framework \Data \Form \FormKey ;
19
19
use Magento \Framework \Message \MessageInterface ;
20
- use Magento \Store \Model \ScopeInterface ;
21
20
use Magento \TestFramework \Helper \Bootstrap ;
22
21
use Magento \TestFramework \Request ;
23
22
use Magento \TestFramework \Response ;
24
23
use Zend \Stdlib \Parameters ;
25
24
use Magento \Framework \App \Request \Http as HttpRequest ;
25
+ use Magento \TestFramework \Mail \Template \TransportBuilderMock ;
26
+ use Magento \Framework \Serialize \Serializer \Json ;
27
+ use Magento \Framework \Stdlib \CookieManagerInterface ;
28
+ use Magento \Theme \Controller \Result \MessagePlugin ;
26
29
27
30
/**
28
31
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
29
32
*/
30
33
class AccountTest extends \Magento \TestFramework \TestCase \AbstractController
31
34
{
35
+ /**
36
+ * @var TransportBuilderMock
37
+ */
38
+ private $ transportBuilderMock ;
39
+
40
+ /**
41
+ * @inheritdoc
42
+ */
43
+ protected function setUp ()
44
+ {
45
+ parent ::setUp ();
46
+ $ this ->transportBuilderMock = $ this ->_objectManager ->get (TransportBuilderMock::class);
47
+ }
48
+
32
49
/**
33
50
* Login the user
34
51
*
@@ -133,11 +150,7 @@ public function testForgotPasswordEmailMessageWithSpecialCharacters()
133
150
$ this ->dispatch ('customer/account/forgotPasswordPost ' );
134
151
$ this ->assertRedirect ($ this ->stringContains ('customer/account/ ' ));
135
152
136
- /** @var \Magento\TestFramework\Mail\Template\TransportBuilderMock $transportBuilder */
137
- $ transportBuilder = $ this ->_objectManager ->get (
138
- \Magento \TestFramework \Mail \Template \TransportBuilderMock::class
139
- );
140
- $ subject = $ transportBuilder ->getSentMessage ()->getSubject ();
153
+ $ subject = $ this ->transportBuilderMock ->getSentMessage ()->getSubject ();
141
154
$ this ->assertContains (
142
155
'Test special \' characters ' ,
143
156
$ subject
@@ -260,65 +273,26 @@ public function testNoFormKeyCreatePostAction()
260
273
/**
261
274
* @magentoDbIsolation enabled
262
275
* @magentoAppIsolation enabled
276
+ * @magentoDataFixture Magento/Customer/_files/customer_confirmation_config_disable.php
263
277
*/
264
278
public function testNoConfirmCreatePostAction ()
265
279
{
266
- /** @var \Magento\Framework\App\Config\MutableScopeConfigInterface $mutableScopeConfig */
267
- $ mutableScopeConfig = Bootstrap::getObjectManager ()
268
- ->get (\Magento \Framework \App \Config \MutableScopeConfigInterface::class);
269
-
270
- $ scopeValue = $ mutableScopeConfig ->getValue (
271
- 'customer/create_account/confirm ' ,
272
- ScopeInterface::SCOPE_WEBSITES ,
273
- null
274
- );
275
-
276
- $ mutableScopeConfig ->setValue (
277
- 'customer/create_account/confirm ' ,
278
- 0 ,
279
- ScopeInterface::SCOPE_WEBSITES ,
280
- null
281
- );
282
-
283
280
$ this ->fillRequestWithAccountDataAndFormKey ('test1@email.com ' );
284
281
$ this ->dispatch ('customer/account/createPost ' );
285
282
$ this ->assertRedirect ($ this ->stringEndsWith ('customer/account/ ' ));
286
283
$ this ->assertSessionMessages (
287
284
$ this ->equalTo (['Thank you for registering with Main Website Store. ' ]),
288
285
MessageInterface::TYPE_SUCCESS
289
286
);
290
-
291
- $ mutableScopeConfig ->setValue (
292
- 'customer/create_account/confirm ' ,
293
- $ scopeValue ,
294
- ScopeInterface::SCOPE_WEBSITES ,
295
- null
296
- );
297
287
}
298
288
299
289
/**
300
290
* @magentoDbIsolation enabled
301
291
* @magentoAppIsolation enabled
292
+ * @magentoDataFixture Magento/Customer/_files/customer_confirmation_config_enable.php
302
293
*/
303
294
public function testWithConfirmCreatePostAction ()
304
295
{
305
- /** @var \Magento\Framework\App\Config\MutableScopeConfigInterface $mutableScopeConfig */
306
- $ mutableScopeConfig = Bootstrap::getObjectManager ()
307
- ->get (\Magento \Framework \App \Config \MutableScopeConfigInterface::class);
308
-
309
- $ scopeValue = $ mutableScopeConfig ->getValue (
310
- 'customer/create_account/confirm ' ,
311
- ScopeInterface::SCOPE_WEBSITES ,
312
- null
313
- );
314
-
315
- $ mutableScopeConfig ->setValue (
316
- 'customer/create_account/confirm ' ,
317
- 1 ,
318
- ScopeInterface::SCOPE_WEBSITES ,
319
- null
320
- );
321
-
322
296
$ this ->fillRequestWithAccountDataAndFormKey ('test2@email.com ' );
323
297
$ this ->dispatch ('customer/account/createPost ' );
324
298
$ this ->assertRedirect ($ this ->stringContains ('customer/account/index/ ' ));
@@ -330,13 +304,6 @@ public function testWithConfirmCreatePostAction()
330
304
]),
331
305
MessageInterface::TYPE_SUCCESS
332
306
);
333
-
334
- $ mutableScopeConfig ->setValue (
335
- 'customer/create_account/confirm ' ,
336
- $ scopeValue ,
337
- ScopeInterface::SCOPE_WEBSITES ,
338
- null
339
- );
340
307
}
341
308
342
309
/**
@@ -730,6 +697,46 @@ public function testLoginPostRedirect($redirectDashboard, string $redirectUrl)
730
697
$ this ->assertTrue ($ this ->_objectManager ->get (Session::class)->isLoggedIn ());
731
698
}
732
699
700
+ /**
701
+ * Test that confirmation email address displays special characters correctly.
702
+ *
703
+ * @magentoDbIsolation enabled
704
+ * @magentoDataFixture Magento/Customer/_files/customer_confirmation_email_address_with_special_chars.php
705
+ *
706
+ * @return void
707
+ */
708
+ public function testConfirmationEmailWithSpecialCharacters (): void
709
+ {
710
+ $ email = 'customer+confirmation@example.com ' ;
711
+ $ this ->dispatch ('customer/account/confirmation/email/customer%2Bconfirmation%40email.com ' );
712
+ $ this ->getRequest ()->setPostValue ('email ' , $ email );
713
+ $ this ->dispatch ('customer/account/confirmation/email/customer%2Bconfirmation%40email.com ' );
714
+
715
+ $ this ->assertRedirect ($ this ->stringContains ('customer/account/index ' ));
716
+ $ this ->assertSessionMessages (
717
+ $ this ->equalTo (['Please check your email for confirmation key. ' ]),
718
+ MessageInterface::TYPE_SUCCESS
719
+ );
720
+
721
+ /** @var $message \Magento\Framework\Mail\Message */
722
+ $ message = $ this ->transportBuilderMock ->getSentMessage ();
723
+ $ rawMessage = $ message ->getRawMessage ();
724
+
725
+ $ this ->assertContains ('To: ' . $ email , $ rawMessage );
726
+
727
+ $ content = $ message ->getBody ()->getPartContent (0 );
728
+ $ confirmationUrl = $ this ->getConfirmationUrlFromMessageContent ($ content );
729
+ $ this ->setRequestInfo ($ confirmationUrl , 'confirm ' );
730
+ $ this ->clearCookieMessagesList ();
731
+ $ this ->dispatch ($ confirmationUrl );
732
+
733
+ $ this ->assertRedirect ($ this ->stringContains ('customer/account/index ' ));
734
+ $ this ->assertSessionMessages (
735
+ $ this ->equalTo (['Thank you for registering with Main Website Store. ' ]),
736
+ MessageInterface::TYPE_SUCCESS
737
+ );
738
+ }
739
+
733
740
/**
734
741
* Data provider for testLoginPostRedirect.
735
742
*
@@ -847,4 +854,53 @@ private function assertResponseRedirect(Response $response, string $redirectUrl)
847
854
$ this ->assertTrue ($ response ->isRedirect ());
848
855
$ this ->assertSame ($ redirectUrl , $ response ->getHeader ('Location ' )->getUri ());
849
856
}
857
+
858
+ /**
859
+ * Add new request info (request uri, path info, action name).
860
+ *
861
+ * @param string $uri
862
+ * @param string $actionName
863
+ * @return void
864
+ */
865
+ private function setRequestInfo (string $ uri , string $ actionName ): void
866
+ {
867
+ $ this ->getRequest ()
868
+ ->setRequestUri ($ uri )
869
+ ->setPathInfo ()
870
+ ->setActionName ($ actionName );
871
+ }
872
+
873
+ /**
874
+ * Clear cookie messages list.
875
+ *
876
+ * @return void
877
+ */
878
+ private function clearCookieMessagesList (): void
879
+ {
880
+ $ cookieManager = $ this ->_objectManager ->get (CookieManagerInterface::class);
881
+ $ jsonSerializer = $ this ->_objectManager ->get (Json::class);
882
+ $ cookieManager ->setPublicCookie (
883
+ MessagePlugin::MESSAGES_COOKIES_NAME ,
884
+ $ jsonSerializer ->serialize ([])
885
+ );
886
+ }
887
+
888
+ /**
889
+ * Get confirmation URL from message content.
890
+ *
891
+ * @param string $content
892
+ * @return string
893
+ */
894
+ private function getConfirmationUrlFromMessageContent (string $ content ): string
895
+ {
896
+ $ confirmationUrl = '' ;
897
+
898
+ if (preg_match ('<a\s*href="(?<url>.*?)".*> ' , $ content , $ matches )) {
899
+ $ confirmationUrl = $ matches ['url ' ];
900
+ $ confirmationUrl = str_replace ('http://localhost/index.php/ ' , '' , $ confirmationUrl );
901
+ $ confirmationUrl = html_entity_decode ($ confirmationUrl );
902
+ }
903
+
904
+ return $ confirmationUrl ;
905
+ }
850
906
}
0 commit comments