@@ -107,6 +107,91 @@ public static function customerDataProvider(): array
107107 ];
108108 }
109109
110+ /**
111+ * Test prepareCustomers with uppercase email in Global scope.
112+ *
113+ * @throws Exception
114+ */
115+ public function testPrepareCustomersWithUppercaseEmailGlobalScope (): void
116+ {
117+ $ customersToFind = [
118+ [
'email ' =>
'[email protected] ' ,
'website_id ' =>
1 ],
119+ ];
120+ $ customersData = [
121+ [
'email ' =>
'[email protected] ' ,
'website_id ' =>
1 ,
'entity_id ' =>
100 ,
'store_id ' =>
1 ],
122+ ];
123+
124+ $ this ->mockCustomerCollectionForGlobalScope ($ customersData );
125+ $ this ->storage ->prepareCustomers ($ customersToFind );
126+
127+ $ this ->
assertEquals (
100 ,
$ this ->
storage ->
getCustomerId (
'[email protected] ' ,
1 ));
128+ $ this ->
assertEquals (
100 ,
$ this ->
storage ->
getCustomerId (
'[email protected] ' ,
1 ));
129+ }
130+
131+ /**
132+ * Test prepareCustomers with uppercase email in Website scope.
133+ *
134+ * @throws Exception
135+ */
136+ public function testPrepareCustomersWithUppercaseEmailWebsiteScope (): void
137+ {
138+ $ customersToFind = [
139+ [
'email ' =>
'[email protected] ' ,
'website_id ' =>
1 ],
140+ ];
141+ $ customersData = [
142+ [
'email ' =>
'[email protected] ' ,
'website_id ' =>
1 ,
'entity_id ' =>
100 ,
'store_id ' =>
1 ],
143+ ];
144+
145+ $ this ->mockCustomerCollectionForWebsiteScope ($ customersData );
146+ $ this ->storage ->prepareCustomers ($ customersToFind );
147+
148+ $ this ->
assertEquals (
100 ,
$ this ->
storage ->
getCustomerId (
'[email protected] ' ,
1 ));
149+ }
150+
151+ /**
152+ * Test prepareCustomers with mixed case emails in Global scope.
153+ *
154+ * @throws Exception
155+ */
156+ public function testPrepareCustomersWithMixedCaseEmailsGlobalScope (): void
157+ {
158+ $ customersToFind = [
159+ [
'email ' =>
'[email protected] ' ,
'website_id ' =>
1 ],
160+ [
'email ' =>
'[email protected] ' ,
'website_id ' =>
2 ],
161+ ];
162+ $ customersData = [
163+ [
'email ' =>
'[email protected] ' ,
'website_id ' =>
1 ,
'entity_id ' =>
200 ,
'store_id ' =>
1 ],
164+ [
'email ' =>
'[email protected] ' ,
'website_id ' =>
2 ,
'entity_id ' =>
201 ,
'store_id ' =>
2 ],
165+ ];
166+
167+ $ this ->mockCustomerCollectionForGlobalScope ($ customersData );
168+ $ this ->storage ->prepareCustomers ($ customersToFind );
169+
170+ $ this ->
assertEquals (
200 ,
$ this ->
storage ->
getCustomerId (
'[email protected] ' ,
1 ));
171+ $ this ->
assertEquals (
201 ,
$ this ->
storage ->
getCustomerId (
'[email protected] ' ,
2 ));
172+ }
173+
174+ /**
175+ * Test email normalization consistency when building customer websites map.
176+ *
177+ * @throws Exception
178+ */
179+ public function testEmailNormalizationConsistency (): void
180+ {
181+ $ customersToFind = [
182+ [
'email ' =>
'[email protected] ' ,
'website_id ' =>
1 ],
183+ ];
184+ $ customersData = [
185+ [
'email ' =>
'[email protected] ' ,
'website_id ' =>
1 ,
'entity_id ' =>
300 ,
'store_id ' =>
1 ],
186+ ];
187+
188+ $ this ->mockCustomerCollectionForGlobalScope ($ customersData );
189+ $ this ->storage ->prepareCustomers ($ customersToFind );
190+
191+ $ this ->
assertEquals (
300 ,
$ this ->
storage ->
getCustomerId (
'[email protected] ' ,
1 ));
192+ $ this ->
assertEquals (
300 ,
$ this ->
storage ->
getCustomerId (
'[email protected] ' ,
1 ));
193+ }
194+
110195 /**
111196 * Mock the customer collection to return specific data.
112197 *
@@ -133,18 +218,94 @@ private function mockCustomerCollection(array $customersData): void
133218 ->willReturn (true );
134219 }
135220
221+ /**
222+ * Mock the customer collection for Global scope tests.
223+ *
224+ * @param array $customersData
225+ * @throws Exception
226+ */
227+ private function mockCustomerCollectionForGlobalScope (array $ customersData ): void
228+ {
229+ $ selectMock = $ this ->getMockBuilder (Select::class)
230+ ->disableOriginalConstructor ()
231+ ->onlyMethods (['getPart ' , 'where ' ])
232+ ->getMock ();
233+
234+ $ selectMock ->expects ($ this ->atLeastOnce ())
235+ ->method ('getPart ' )
236+ ->willReturn (['main_table ' => 'customer_entity ' ]);
237+
238+ $ selectMock ->method ('where ' )
239+ ->willReturnSelf ();
240+
241+ $ this ->customerCollectionMock ->expects ($ this ->atLeastOnce ())
242+ ->method ('removeAttributeToSelect ' )
243+ ->willReturnSelf ();
244+
245+ $ this ->customerCollectionMock ->expects ($ this ->atLeastOnce ())
246+ ->method ('getSelect ' )
247+ ->willReturn ($ selectMock );
248+
249+ $ this ->customerCollectionMock ->expects ($ this ->atLeastOnce ())
250+ ->method ('getConnection ' )
251+ ->willReturn ($ this ->mockConnection ($ customersData ));
252+
253+ $ this ->configShareMock ->expects ($ this ->atLeastOnce ())
254+ ->method ('isGlobalScope ' )
255+ ->willReturn (true );
256+ }
257+
258+ /**
259+ * Mock the customer collection for Website scope tests.
260+ *
261+ * @param array $customersData
262+ * @throws Exception
263+ */
264+ private function mockCustomerCollectionForWebsiteScope (array $ customersData ): void
265+ {
266+ $ selectMock = $ this ->getMockBuilder (Select::class)
267+ ->disableOriginalConstructor ()
268+ ->onlyMethods (['getPart ' , 'where ' ])
269+ ->getMock ();
270+
271+ $ selectMock ->expects ($ this ->atLeastOnce ())
272+ ->method ('getPart ' )
273+ ->willReturn (['main_table ' => 'customer_entity ' ]);
274+
275+ $ selectMock ->method ('where ' )
276+ ->willReturnSelf ();
277+
278+ $ this ->customerCollectionMock ->expects ($ this ->atLeastOnce ())
279+ ->method ('removeAttributeToSelect ' )
280+ ->willReturnSelf ();
281+
282+ $ this ->customerCollectionMock ->expects ($ this ->atLeastOnce ())
283+ ->method ('getSelect ' )
284+ ->willReturn ($ selectMock );
285+
286+ $ this ->customerCollectionMock ->expects ($ this ->atLeastOnce ())
287+ ->method ('getConnection ' )
288+ ->willReturn ($ this ->mockConnection ($ customersData ));
289+
290+ $ this ->configShareMock ->expects ($ this ->atLeastOnce ())
291+ ->method ('isGlobalScope ' )
292+ ->willReturn (false );
293+ }
294+
136295 /**
137296 * Mock the database connection to return specific customer data.
138297 *
139298 * @param array $customersData
140299 * @return MockObject
300+ * @throws Exception
141301 */
142302 private function mockConnection (array $ customersData ): MockObject
143303 {
144- $ this ->connectionMock ->expects ($ this ->once ())
304+ $ connectionMock = $ this ->createMock (AdapterInterface::class);
305+ $ connectionMock ->expects ($ this ->once ())
145306 ->method ('fetchAll ' )
146307 ->willReturn ($ customersData );
147308
148- return $ this -> connectionMock ;
309+ return $ connectionMock ;
149310 }
150311}
0 commit comments