10
10
use Magento \Customer \Api \AccountManagementInterface ;
11
11
use Magento \Customer \Model \AccountManagement ;
12
12
use Magento \Framework \ObjectManagerInterface ;
13
+ use Magento \Store \Model \StoreManagerInterface ;
13
14
use Magento \TestFramework \Helper \Bootstrap ;
14
15
use Magento \TestFramework \Helper \Xpath ;
15
16
use Magento \TestFramework \Mail \Template \TransportBuilderMock ;
@@ -35,6 +36,9 @@ class ForgotPasswordTest extends TestCase
35
36
private $ newPasswordLinkPath = "//a[contains(@href, 'customer/account/createPassword') "
36
37
. "and contains(text(), 'Set a New Password')] " ;
37
38
39
+ /** @var StoreManagerInterface */
40
+ private $ storeManager ;
41
+
38
42
/**
39
43
* @inheritdoc
40
44
*/
@@ -45,6 +49,7 @@ protected function setUp(): void
45
49
$ this ->objectManager = Bootstrap::getObjectManager ();
46
50
$ this ->accountManagement = $ this ->objectManager ->get (AccountManagementInterface::class);
47
51
$ this ->transportBuilder = $ this ->objectManager ->get (TransportBuilderMock::class);
52
+ $ this ->storeManager = $ this ->objectManager ->get (StoreManagerInterface::class);
48
53
}
49
54
50
55
/**
@@ -61,4 +66,44 @@ public function testForgotPassword(): void
61
66
$ this ->assertTrue ($ result );
62
67
$ this ->assertEquals (1 , Xpath::getElementsCountForXpath ($ this ->newPasswordLinkPath , $ messageContent ));
63
68
}
69
+
70
+ /**
71
+ * @magentoDataFixture Magento/Customer/_files/customer.php
72
+ *
73
+ * @return void
74
+ */
75
+ public function testResetPasswordFlowStorefront (): void
76
+ {
77
+ // Forgot password section
78
+ $ email = 'customer@example.com ' ;
79
+ $ result = $ this ->accountManagement ->initiatePasswordReset ($ email , AccountManagement::EMAIL_RESET );
80
+ $ message = $ this ->transportBuilder ->getSentMessage ();
81
+ $ messageContent = $ message ->getBody ()->getParts ()[0 ]->getRawContent ();
82
+ $ this ->assertTrue ($ result );
83
+ $ this ->assertEquals (1 , Xpath::getElementsCountForXpath ($ this ->newPasswordLinkPath , $ messageContent ));
84
+
85
+ // Send reset password link
86
+ $ websiteId = (int )$ this ->storeManager ->getWebsite ('base ' )->getId ();
87
+ $ this ->accountManagement ->initiatePasswordReset ($ email , AccountManagement::EMAIL_RESET , $ websiteId );
88
+
89
+ // login with old credentials
90
+ $ customer = $ this ->accountManagement ->authenticate ('customer@example.com ' , 'password ' );
91
+
92
+ $ this ->assertEquals (
93
+ $ customer ->getId (),
94
+ $ this ->accountManagement ->authenticate ('customer@example.com ' , 'password ' )->getId ()
95
+ );
96
+
97
+ // Change password
98
+ $ this ->accountManagement ->changePassword ('customer@example.com ' , 'password ' , 'new_Password123 ' );
99
+
100
+ // Login with new credentials
101
+ $ this ->accountManagement ->authenticate ('customer@example.com ' , 'new_Password123 ' );
102
+
103
+ $ this ->assertEquals (
104
+ $ customer ->getId (),
105
+ $ this ->accountManagement ->authenticate ('customer@example.com ' , 'new_Password123 ' )->getId ()
106
+ );
107
+
108
+ }
64
109
}
0 commit comments