7
7
8
8
namespace Magento \Customer \Model \AccountManagement ;
9
9
10
+ use Magento \Catalog \Helper \Data ;
10
11
use Magento \Customer \Api \AccountManagementInterface ;
11
- use Magento \Customer \Api \CustomerRepositoryInterface ;
12
12
use Magento \Customer \Model \AccountManagement ;
13
+ use Magento \Customer \Test \Fixture \Customer ;
14
+ use Magento \Framework \Exception \LocalizedException ;
13
15
use Magento \Framework \ObjectManagerInterface ;
14
16
use Magento \Store \Model \StoreManagerInterface ;
17
+ use Magento \Store \Test \Fixture \Group as StoreGroupFixture ;
18
+ use Magento \Store \Test \Fixture \Store as StoreFixture ;
19
+ use Magento \Store \Test \Fixture \Website as WebsiteFixture ;
20
+ use Magento \TestFramework \Fixture \Config ;
21
+ use Magento \TestFramework \Fixture \DataFixture ;
22
+ use Magento \TestFramework \Fixture \DataFixtureStorage ;
23
+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
15
24
use Magento \TestFramework \Helper \Bootstrap ;
16
25
use Magento \TestFramework \Helper \Xpath ;
17
26
use Magento \TestFramework \Mail \Template \TransportBuilderMock ;
@@ -40,8 +49,8 @@ class ForgotPasswordTest extends TestCase
40
49
/** @var StoreManagerInterface */
41
50
private $ storeManager ;
42
51
43
- /** @var CustomerRepositoryInterface */
44
- private $ customerRepository ;
52
+ /** @var DataFixtureStorage */
53
+ private $ fixtures ;
45
54
46
55
/**
47
56
* @inheritdoc
@@ -54,7 +63,7 @@ protected function setUp(): void
54
63
$ this ->accountManagement = $ this ->objectManager ->get (AccountManagementInterface::class);
55
64
$ this ->transportBuilder = $ this ->objectManager ->get (TransportBuilderMock::class);
56
65
$ this ->storeManager = $ this ->objectManager ->get (StoreManagerInterface::class);
57
- $ this ->customerRepository = $ this ->objectManager ->get (CustomerRepositoryInterface ::class);
66
+ $ this ->fixtures = $ this ->objectManager ->get (DataFixtureStorageManager ::class)-> getStorage ( );
58
67
}
59
68
60
69
/**
@@ -73,29 +82,46 @@ public function testForgotPassword(): void
73
82
}
74
83
75
84
/**
76
- * @magentoDataFixture Magento/Customer/_files/customer.php
77
- *
78
85
* @return void
86
+ * @throws LocalizedException
79
87
*/
88
+ #[
89
+ Config(Data::XML_PATH_PRICE_SCOPE , Data::PRICE_SCOPE_WEBSITE ),
90
+ DataFixture(WebsiteFixture::class, as: 'website2 ' ),
91
+ DataFixture(StoreGroupFixture::class, ['website_id ' => '$website2.id$ ' ], 'store_group2 ' ),
92
+ DataFixture(StoreFixture::class, ['store_group_id ' => '$store_group2.id$ ' ], 'store2 ' ),
93
+ DataFixture(StoreFixture::class, ['store_group_id ' => '$store_group2.id$ ' ], 'store3 ' ),
94
+ DataFixture(
95
+ Customer::class,
96
+ [
97
+ 'store_id ' => '$store2.id$ ' ,
98
+ 'website_id ' => '1 ' ,
99
+ 'addresses ' => [[]]
100
+ ],
101
+ as: 'customer '
102
+ )
103
+ ]
80
104
public function testResetPasswordFlowStorefront (): void
81
105
{
82
- // Forgot password section
83
- $ email = 'customer@example.com ' ;
84
- $ customerId = (int )$ this ->customerRepository ->get ($ email )->getId ();
106
+ // Forgot password section;
107
+ $ customer = $ this ->fixtures ->get ('customer ' );
108
+ $ email = $ customer ->getEmail ();
109
+ $ customer ->getId ();
110
+ $ customerId = (int )$ customer ->getId ();
85
111
$ result = $ this ->accountManagement ->initiatePasswordReset ($ email , AccountManagement::EMAIL_RESET );
86
112
$ message = $ this ->transportBuilder ->getSentMessage ();
87
113
$ messageContent = $ message ->getBody ()->getParts ()[0 ]->getRawContent ();
88
114
$ this ->assertTrue ($ result );
89
115
$ this ->assertEquals (1 , Xpath::getElementsCountForXpath ($ this ->newPasswordLinkPath , $ messageContent ));
90
116
91
117
// Send reset password link
92
- $ websiteId = (int )$ this ->storeManager ->getWebsite ('base ' )->getId ();
93
- $ this ->accountManagement ->initiatePasswordReset ($ email , AccountManagement::EMAIL_RESET , $ websiteId );
118
+ $ defaultWebsiteId = (int )$ this ->storeManager ->getWebsite ('base ' )->getId ();
119
+ $ this ->accountManagement ->initiatePasswordReset ($ email , AccountManagement::EMAIL_RESET , $ defaultWebsiteId );
94
120
95
121
// login with old credentials
96
122
$ this ->assertEquals (
97
123
$ customerId ,
98
- $ this ->accountManagement ->authenticate ($ email , 'password ' )->getId ()
124
+ ( int ) $ this ->accountManagement ->authenticate ($ email , 'password ' )->getId ()
99
125
);
100
126
101
127
// Change password
0 commit comments