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