19
19
use Magento \Framework \App \Http ;
20
20
use Magento \Framework \Data \Form \FormKey ;
21
21
use Magento \Framework \Message \MessageInterface ;
22
- use Magento \Store \Model \ScopeInterface ;
23
22
use Magento \TestFramework \Helper \Bootstrap ;
24
23
use Magento \TestFramework \Request ;
25
24
use Magento \TestFramework \Response ;
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
use Zend \Stdlib \Parameters ;
27
30
28
31
/**
29
32
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
30
33
*/
31
34
class AccountTest extends \Magento \TestFramework \TestCase \AbstractController
32
35
{
36
+ /**
37
+ * @var TransportBuilderMock
38
+ */
39
+ private $ transportBuilderMock ;
40
+
41
+ /**
42
+ * @inheritdoc
43
+ */
44
+ protected function setUp ()
45
+ {
46
+ parent ::setUp ();
47
+ $ this ->transportBuilderMock = $ this ->_objectManager ->get (TransportBuilderMock::class);
48
+ }
49
+
33
50
/**
34
51
* Login the user
35
52
*
@@ -102,11 +119,7 @@ public function testForgotPasswordEmailMessageWithSpecialCharacters()
102
119
$ this ->dispatch ('customer/account/forgotPasswordPost ' );
103
120
$ this ->assertRedirect ($ this ->stringContains ('customer/account/ ' ));
104
121
105
- /** @var \Magento\TestFramework\Mail\Template\TransportBuilderMock $transportBuilder */
106
- $ transportBuilder = $ this ->_objectManager ->get (
107
- \Magento \TestFramework \Mail \Template \TransportBuilderMock::class
108
- );
109
- $ subject = $ transportBuilder ->getSentMessage ()->getSubject ();
122
+ $ subject = $ this ->transportBuilderMock ->getSentMessage ()->getSubject ();
110
123
$ this ->assertContains (
111
124
'Test special \' characters ' ,
112
125
$ subject
@@ -228,65 +241,26 @@ public function testNoFormKeyCreatePostAction()
228
241
/**
229
242
* @magentoDbIsolation enabled
230
243
* @magentoAppIsolation enabled
244
+ * @magentoDataFixture Magento/Customer/_files/customer_confirmation_config_disable.php
231
245
*/
232
246
public function testNoConfirmCreatePostAction ()
233
247
{
234
- /** @var \Magento\Framework\App\Config\MutableScopeConfigInterface $mutableScopeConfig */
235
- $ mutableScopeConfig = Bootstrap::getObjectManager ()
236
- ->get (\Magento \Framework \App \Config \MutableScopeConfigInterface::class);
237
-
238
- $ scopeValue = $ mutableScopeConfig ->getValue (
239
- 'customer/create_account/confirm ' ,
240
- ScopeInterface::SCOPE_WEBSITES ,
241
- null
242
- );
243
-
244
- $ mutableScopeConfig ->setValue (
245
- 'customer/create_account/confirm ' ,
246
- 0 ,
247
- ScopeInterface::SCOPE_WEBSITES ,
248
- null
249
- );
250
-
251
248
$ this ->fillRequestWithAccountDataAndFormKey ();
252
249
$ this ->dispatch ('customer/account/createPost ' );
253
250
$ this ->assertRedirect ($ this ->stringEndsWith ('customer/account/ ' ));
254
251
$ this ->assertSessionMessages (
255
252
$ this ->equalTo (['Thank you for registering with Main Website Store. ' ]),
256
253
MessageInterface::TYPE_SUCCESS
257
254
);
258
-
259
- $ mutableScopeConfig ->setValue (
260
- 'customer/create_account/confirm ' ,
261
- $ scopeValue ,
262
- ScopeInterface::SCOPE_WEBSITES ,
263
- null
264
- );
265
255
}
266
256
267
257
/**
268
258
* @magentoDbIsolation enabled
269
259
* @magentoAppIsolation enabled
260
+ * @magentoDataFixture Magento/Customer/_files/customer_confirmation_config_enable.php
270
261
*/
271
262
public function testWithConfirmCreatePostAction ()
272
263
{
273
- /** @var \Magento\Framework\App\Config\MutableScopeConfigInterface $mutableScopeConfig */
274
- $ mutableScopeConfig = Bootstrap::getObjectManager ()
275
- ->get (\Magento \Framework \App \Config \MutableScopeConfigInterface::class);
276
-
277
- $ scopeValue = $ mutableScopeConfig ->getValue (
278
- 'customer/create_account/confirm ' ,
279
- ScopeInterface::SCOPE_WEBSITES ,
280
- null
281
- );
282
-
283
- $ mutableScopeConfig ->setValue (
284
- 'customer/create_account/confirm ' ,
285
- 1 ,
286
- ScopeInterface::SCOPE_WEBSITES ,
287
- null
288
- );
289
-
290
264
$ this ->fillRequestWithAccountDataAndFormKey ();
291
265
$ this ->dispatch ('customer/account/createPost ' );
292
266
$ this ->assertRedirect ($ this ->stringContains ('customer/account/index/ ' ));
@@ -298,13 +272,6 @@ public function testWithConfirmCreatePostAction()
298
272
]),
299
273
MessageInterface::TYPE_SUCCESS
300
274
);
301
-
302
- $ mutableScopeConfig ->setValue (
303
- 'customer/create_account/confirm ' ,
304
- $ scopeValue ,
305
- ScopeInterface::SCOPE_WEBSITES ,
306
- null
307
- );
308
275
}
309
276
310
277
/**
@@ -690,6 +657,46 @@ public function testLoginPostRedirect($redirectDashboard, string $redirectUrl)
690
657
$ this ->assertTrue ($ this ->_objectManager ->get (Session::class)->isLoggedIn ());
691
658
}
692
659
660
+ /**
661
+ * Test that confirmation email address displays special characters correctly.
662
+ *
663
+ * @magentoDbIsolation enabled
664
+ * @magentoDataFixture Magento/Customer/_files/customer_confirmation_email_address_with_special_chars.php
665
+ *
666
+ * @return void
667
+ */
668
+ public function testConfirmationEmailWithSpecialCharacters ()
669
+ {
670
+ $ email = 'customer+confirmation@example.com ' ;
671
+ $ this ->dispatch ('customer/account/confirmation/email/customer%2Bconfirmation%40email.com ' );
672
+ $ this ->getRequest ()->setPostValue ('email ' , $ email );
673
+ $ this ->dispatch ('customer/account/confirmation/email/customer%2Bconfirmation%40email.com ' );
674
+
675
+ $ this ->assertRedirect ($ this ->stringContains ('customer/account/index ' ));
676
+ $ this ->assertSessionMessages (
677
+ $ this ->equalTo (['Please check your email for confirmation key. ' ]),
678
+ MessageInterface::TYPE_SUCCESS
679
+ );
680
+
681
+ /** @var $message \Magento\Framework\Mail\Message */
682
+ $ message = $ this ->transportBuilderMock ->getSentMessage ();
683
+ $ rawMessage = $ message ->getRawMessage ();
684
+
685
+ $ this ->assertContains ('To: ' . $ email , $ rawMessage );
686
+
687
+ $ content = $ message ->getBody ()->getPartContent (0 );
688
+ $ confirmationUrl = $ this ->getConfirmationUrlFromMessageContent ($ content );
689
+ $ this ->setRequestInfo ($ confirmationUrl , 'confirm ' );
690
+ $ this ->clearCookieMessagesList ();
691
+ $ this ->dispatch ($ confirmationUrl );
692
+
693
+ $ this ->assertRedirect ($ this ->stringContains ('customer/account/index ' ));
694
+ $ this ->assertSessionMessages (
695
+ $ this ->equalTo (['Thank you for registering with Main Website Store. ' ]),
696
+ MessageInterface::TYPE_SUCCESS
697
+ );
698
+ }
699
+
693
700
/**
694
701
* Data provider for testLoginPostRedirect.
695
702
*
@@ -705,16 +712,17 @@ public function loginPostRedirectDataProvider()
705
712
}
706
713
707
714
/**
715
+ * @param string $email
708
716
* @return void
709
717
*/
710
- private function fillRequestWithAccountData ()
718
+ private function fillRequestWithAccountData (string $ email = ' test1@email.com ' )
711
719
{
712
720
$ this ->getRequest ()
713
721
->setMethod ('POST ' )
714
722
->setParam ('firstname ' , 'firstname1 ' )
715
723
->setParam ('lastname ' , 'lastname1 ' )
716
724
->setParam ('company ' , '' )
717
- ->setParam ('email ' , ' test1@ email.com ' )
725
+ ->setParam ('email ' , $ email )
718
726
->setParam ('password ' , '_Password1 ' )
719
727
->setParam ('password_confirmation ' , '_Password1 ' )
720
728
->setParam ('telephone ' , '5123334444 ' )
@@ -731,11 +739,12 @@ private function fillRequestWithAccountData()
731
739
}
732
740
733
741
/**
742
+ * @param string $email
734
743
* @return void
735
744
*/
736
- private function fillRequestWithAccountDataAndFormKey ()
745
+ private function fillRequestWithAccountDataAndFormKey (string $ email = ' test1@email.com ' )
737
746
{
738
- $ this ->fillRequestWithAccountData ();
747
+ $ this ->fillRequestWithAccountData ($ email );
739
748
$ formKey = $ this ->_objectManager ->get (FormKey::class);
740
749
$ this ->getRequest ()->setParam ('form_key ' , $ formKey ->getFormKey ());
741
750
}
@@ -805,4 +814,53 @@ private function assertResponseRedirect(Response $response, string $redirectUrl)
805
814
$ this ->assertTrue ($ response ->isRedirect ());
806
815
$ this ->assertSame ($ redirectUrl , $ response ->getHeader ('Location ' )->getUri ());
807
816
}
817
+
818
+ /**
819
+ * Add new request info (request uri, path info, action name).
820
+ *
821
+ * @param string $uri
822
+ * @param string $actionName
823
+ * @return void
824
+ */
825
+ private function setRequestInfo (string $ uri , string $ actionName )
826
+ {
827
+ $ this ->getRequest ()
828
+ ->setRequestUri ($ uri )
829
+ ->setPathInfo ()
830
+ ->setActionName ($ actionName );
831
+ }
832
+
833
+ /**
834
+ * Clear cookie messages list.
835
+ *
836
+ * @return void
837
+ */
838
+ private function clearCookieMessagesList ()
839
+ {
840
+ $ cookieManager = $ this ->_objectManager ->get (CookieManagerInterface::class);
841
+ $ jsonSerializer = $ this ->_objectManager ->get (Json::class);
842
+ $ cookieManager ->setPublicCookie (
843
+ MessagePlugin::MESSAGES_COOKIES_NAME ,
844
+ $ jsonSerializer ->serialize ([])
845
+ );
846
+ }
847
+
848
+ /**
849
+ * Get confirmation URL from message content.
850
+ *
851
+ * @param string $content
852
+ * @return string
853
+ */
854
+ private function getConfirmationUrlFromMessageContent (string $ content ): string
855
+ {
856
+ $ confirmationUrl = '' ;
857
+
858
+ if (preg_match ('<a\s*href="(?<url>.*?)".*> ' , $ content , $ matches )) {
859
+ $ confirmationUrl = $ matches ['url ' ];
860
+ $ confirmationUrl = str_replace ('http://localhost/index.php/ ' , '' , $ confirmationUrl );
861
+ $ confirmationUrl = html_entity_decode ($ confirmationUrl );
862
+ }
863
+
864
+ return $ confirmationUrl ;
865
+ }
808
866
}
0 commit comments