Skip to content

Commit f3c4042

Browse files
committed
Guest print order form fixes
1 parent 878b1c9 commit f3c4042

File tree

5 files changed

+134
-14
lines changed

5 files changed

+134
-14
lines changed

app/code/Magento/Sales/Helper/Guest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ public function loadValidOrder(App\RequestInterface $request)
151151
return $this->resultRedirectFactory->create()->setPath('sales/order/history');
152152
}
153153
$post = $request->getPostValue();
154+
$post = filter_var($post, FILTER_CALLBACK, ['options' => 'trim']);
154155
$fromCookie = $this->cookieManager->getCookie(self::COOKIE_NAME);
155156
if (empty($post) && !$fromCookie) {
156157
return $this->resultRedirectFactory->create()->setPath('sales/guest/form');
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="StorefrontFillOrdersAndReturnsFormTypeZipActionGroup">
12+
<arguments>
13+
<argument name="orderNumber" type="string"/>
14+
<argument name="customer" type="entity"/>
15+
<argument name="address" type="entity"/>
16+
</arguments>
17+
<fillField selector="{{StorefrontGuestOrderSearchSection.orderId}}" userInput="{{orderNumber}}" stepKey="inputOrderId"/>
18+
<fillField selector="{{StorefrontGuestOrderSearchSection.billingLastName}}" userInput="{{customer.lastname}}" stepKey="inputBillingLastName"/>
19+
<selectOption selector="{{StorefrontGuestOrderSearchSection.findOrderBy}}" userInput="zip" stepKey="selectFindOrderByZip"/>
20+
<fillField selector="{{StorefrontGuestOrderSearchSection.zip}}" userInput="{{address.postcode}}" stepKey="inputZip"/>
21+
</actionGroup>
22+
</actionGroups>

app/code/Magento/Sales/Test/Mftf/Section/StorefrontGuestOrderSearchSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<element name="billingLastName" type="input" selector="#oar-billing-lastname"/>
1414
<element name="findOrderBy" type="select" selector="#quick-search-type-id"/>
1515
<element name="email" type="input" selector="#oar_email"/>
16+
<element name="zip" type="input" selector="#oar_zip"/>
1617
<element name="continue" type="button" selector="//*/span[contains(text(), 'Continue')]"/>
1718
</section>
1819
</sections>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="StorefrontPrintOrderFindByZipGuestTest" extends="StorefrontPrintOrderGuestTest">
12+
<annotations>
13+
<stories value="Print Order"/>
14+
<title value="Print Order from Guest on Frontend using Zip for search"/>
15+
<description value="Print Order from Guest on Frontend"/>
16+
<severity value="BLOCKER"/>
17+
<testCaseId value="MC-16225"/>
18+
<group value="sales"/>
19+
</annotations>
20+
21+
<remove keyForRemoval="fillOrder"/>
22+
23+
<!-- Fill the form with correspondent Order data using search by Zip -->
24+
<actionGroup ref="StorefrontFillOrdersAndReturnsFormTypeZipActionGroup" stepKey="fillOrderZip" before="clickContinue">
25+
<argument name="orderNumber" value="{$getOrderId}"/>
26+
<argument name="customer" value="$$createCustomer$$"/>
27+
<argument name="address" value="US_Address_TX"/>
28+
</actionGroup>
29+
</test>
30+
</tests>

app/code/Magento/Sales/Test/Unit/Helper/GuestTest.php

Lines changed: 80 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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,44 @@ 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')->willReturn(trim($post['oar_billing_lastname']));
186+
$billingAddressMock->expects($this->any())->method('getEmail')->willReturn(trim($post['oar_email']));
187+
$billingAddressMock->expects($this->any())->method('getPostcode')->willReturn(trim($post['oar_zip']));
174188
$this->salesOrderMock->expects($this->once())->method('getBillingAddress')->willReturn($billingAddressMock);
175189
$this->salesOrderMock->expects($this->once())->method('getProtectCode')->willReturn($protectedCode);
176190
$metaDataMock = $this->createMock(PublicCookieMetadata::class);
@@ -190,17 +204,69 @@ public function testLoadValidOrderNotEmptyPost()
190204
$this->assertTrue($this->guest->loadValidOrder($requestMock));
191205
}
192206

207+
/**
208+
* Load valid order with non empty post data provider.
209+
*
210+
* @return array
211+
*/
212+
public function loadValidOrderNotEmptyPostDataProvider()
213+
{
214+
return [
215+
[
216+
[
217+
'oar_order_id' => '1',
218+
'oar_type' => 'email',
219+
'oar_billing_lastname' => 'White',
220+
'oar_email' => 'test@magento-test.com',
221+
'oar_zip' => '',
222+
223+
]
224+
],
225+
[
226+
[
227+
'oar_order_id' => ' 14 ',
228+
'oar_type' => 'email',
229+
'oar_billing_lastname' => 'Black ',
230+
'oar_email' => ' test1@magento-test.com ',
231+
'oar_zip' => '',
232+
]
233+
],
234+
[
235+
[
236+
'oar_order_id' => ' 14 ',
237+
'oar_type' => 'zip',
238+
'oar_billing_lastname' => 'Black ',
239+
'oar_email' => ' test1@magento-test.com ',
240+
'oar_zip' => '123456 ',
241+
]
242+
]
243+
];
244+
}
245+
193246
public function testLoadValidOrderStoredCookie()
194247
{
195248
$protectedCode = 'protectedCode';
196-
$incrementId = 1;
249+
$incrementId = '1';
197250
$cookieData = $protectedCode . ':' . $incrementId;
198251
$cookieDataHash = base64_encode($cookieData);
199252
$this->sessionMock->expects($this->once())->method('isLoggedIn')->willReturn(false);
200253
$this->cookieManagerMock->expects($this->once())
201254
->method('getCookie')
202255
->with(Guest::COOKIE_NAME)
203256
->willReturn($cookieDataHash);
257+
258+
$this->searchCriteriaBuilder
259+
->expects($this->at(0))
260+
->method('addFilter')
261+
->with('increment_id', trim($incrementId))
262+
->willReturnSelf();
263+
264+
$this->searchCriteriaBuilder
265+
->expects($this->at(1))
266+
->method('addFilter')
267+
->with('store_id', $this->storeModelMock->getId())
268+
->willReturnSelf();
269+
204270
$this->salesOrderMock->expects($this->any())->method('getId')->willReturn($incrementId);
205271
$this->salesOrderMock->expects($this->once())->method('getProtectCode')->willReturn($protectedCode);
206272
$metaDataMock = $this->createMock(PublicCookieMetadata::class);

0 commit comments

Comments
 (0)