@@ -112,7 +112,6 @@ protected function setUp(): void
112112 ->setMethods (['getTotalCount ' , 'getItems ' ])
113113 ->disableOriginalConstructor ()
114114 ->getMockForAbstractClass ();
115- $ this ->searchCriteriaBuilder ->method ('addFilter ' )->willReturnSelf ();
116115 $ resultRedirectFactory =
117116 $ this ->getMockBuilder (RedirectFactory::class)
118117 ->setMethods (['create ' ])
@@ -148,29 +147,45 @@ protected function setUp(): void
148147 );
149148 }
150149
151- public function testLoadValidOrderNotEmptyPost ()
150+ /**
151+ * Test load valid order with non empty post data.
152+ *
153+ * @param array $post
154+ * @dataProvider loadValidOrderNotEmptyPostDataProvider
155+ * @throws \Magento\Framework\Exception\InputException
156+ * @throws \Magento\Framework\Stdlib\Cookie\CookieSizeLimitReachedException
157+ * @throws \Magento\Framework\Stdlib\Cookie\FailureToSendException
158+ */
159+ public function testLoadValidOrderNotEmptyPost ($ post )
152160 {
153- $ post = [
154- 'oar_order_id ' => 1 ,
155- 'oar_type ' => 'email ' ,
156- 'oar_billing_lastname ' => 'oar_billing_lastname ' ,
157- 'oar_email ' => 'oar_email ' ,
158- 'oar_zip ' => 'oar_zip ' ,
159-
160- ];
161161 $ incrementId = $ post ['oar_order_id ' ];
162162 $ protectedCode = 'protectedCode ' ;
163163 $ this ->sessionMock ->expects ($ this ->once ())->method ('isLoggedIn ' )->willReturn (false );
164164 $ requestMock = $ this ->createMock (Http::class);
165165 $ requestMock ->expects ($ this ->once ())->method ('getPostValue ' )->willReturn ($ post );
166+
167+ $ this ->searchCriteriaBuilder
168+ ->expects ($ this ->at (0 ))
169+ ->method ('addFilter ' )
170+ ->with ('increment_id ' , trim ($ incrementId ))
171+ ->willReturnSelf ();
172+
173+ $ this ->searchCriteriaBuilder
174+ ->expects ($ this ->at (1 ))
175+ ->method ('addFilter ' )
176+ ->with ('store_id ' , $ this ->storeModelMock ->getId ())
177+ ->willReturnSelf ();
178+
166179 $ this ->salesOrderMock ->expects ($ this ->any ())->method ('getId ' )->willReturn ($ incrementId );
167180
168181 $ billingAddressMock = $ this ->createPartialMock (
169182 Address::class,
170- ['getLastname ' , 'getEmail ' ]
183+ ['getLastname ' , 'getEmail ' , ' getPostcode ' ]
171184 );
172- $ billingAddressMock ->expects ($ this ->once ())->method ('getLastname ' )->willReturn (($ post ['oar_billing_lastname ' ]));
173- $ billingAddressMock ->expects ($ this ->once ())->method ('getEmail ' )->willReturn (($ post ['oar_email ' ]));
185+ $ billingAddressMock ->expects ($ this ->once ())->method ('getLastname ' )
186+ ->willReturn (trim ($ post ['oar_billing_lastname ' ]));
187+ $ billingAddressMock ->expects ($ this ->any ())->method ('getEmail ' )->willReturn (trim ($ post ['oar_email ' ]));
188+ $ billingAddressMock ->expects ($ this ->any ())->method ('getPostcode ' )->willReturn (trim ($ post ['oar_zip ' ]));
174189 $ this ->salesOrderMock ->expects ($ this ->once ())->method ('getBillingAddress ' )->willReturn ($ billingAddressMock );
175190 $ this ->salesOrderMock ->expects ($ this ->once ())->method ('getProtectCode ' )->willReturn ($ protectedCode );
176191 $ metaDataMock = $ this ->createMock (PublicCookieMetadata::class);
@@ -190,17 +205,69 @@ public function testLoadValidOrderNotEmptyPost()
190205 $ this ->assertTrue ($ this ->guest ->loadValidOrder ($ requestMock ));
191206 }
192207
208+ /**
209+ * Load valid order with non empty post data provider.
210+ *
211+ * @return array
212+ */
213+ public function loadValidOrderNotEmptyPostDataProvider ()
214+ {
215+ return [
216+ [
217+ [
218+ 'oar_order_id ' => '1 ' ,
219+ 'oar_type ' => 'email ' ,
220+ 'oar_billing_lastname ' => 'White ' ,
221+ 'oar_email ' => 'test@magento-test.com ' ,
222+ 'oar_zip ' => '' ,
223+
224+ ]
225+ ],
226+ [
227+ [
228+ 'oar_order_id ' => ' 14 ' ,
229+ 'oar_type ' => 'email ' ,
230+ 'oar_billing_lastname ' => 'Black ' ,
231+ 'oar_email ' => ' test1@magento-test.com ' ,
232+ 'oar_zip ' => '' ,
233+ ]
234+ ],
235+ [
236+ [
237+ 'oar_order_id ' => ' 14 ' ,
238+ 'oar_type ' => 'zip ' ,
239+ 'oar_billing_lastname ' => 'Black ' ,
240+ 'oar_email ' => ' test1@magento-test.com ' ,
241+ 'oar_zip ' => '123456 ' ,
242+ ]
243+ ]
244+ ];
245+ }
246+
193247 public function testLoadValidOrderStoredCookie ()
194248 {
195249 $ protectedCode = 'protectedCode ' ;
196- $ incrementId = 1 ;
250+ $ incrementId = ' 1 ' ;
197251 $ cookieData = $ protectedCode . ': ' . $ incrementId ;
198252 $ cookieDataHash = base64_encode ($ cookieData );
199253 $ this ->sessionMock ->expects ($ this ->once ())->method ('isLoggedIn ' )->willReturn (false );
200254 $ this ->cookieManagerMock ->expects ($ this ->once ())
201255 ->method ('getCookie ' )
202256 ->with (Guest::COOKIE_NAME )
203257 ->willReturn ($ cookieDataHash );
258+
259+ $ this ->searchCriteriaBuilder
260+ ->expects ($ this ->at (0 ))
261+ ->method ('addFilter ' )
262+ ->with ('increment_id ' , trim ($ incrementId ))
263+ ->willReturnSelf ();
264+
265+ $ this ->searchCriteriaBuilder
266+ ->expects ($ this ->at (1 ))
267+ ->method ('addFilter ' )
268+ ->with ('store_id ' , $ this ->storeModelMock ->getId ())
269+ ->willReturnSelf ();
270+
204271 $ this ->salesOrderMock ->expects ($ this ->any ())->method ('getId ' )->willReturn ($ incrementId );
205272 $ this ->salesOrderMock ->expects ($ this ->once ())->method ('getProtectCode ' )->willReturn ($ protectedCode );
206273 $ metaDataMock = $ this ->createMock (PublicCookieMetadata::class);
0 commit comments