Skip to content

Commit 5f0671d

Browse files
authored
ENGCOM-8044: Guest print order form fixes #29309
2 parents ff24a4b + dc1560f commit 5f0671d

File tree

6 files changed

+150
-17
lines changed

6 files changed

+150
-17
lines changed

app/code/Magento/LoginAsCustomer/Test/Mftf/Test/AdminUIShownIfLoginAsCustomerEnabledTest.xml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,18 @@
2323
stepKey="enableLoginAsCustomer"/>
2424
<magentoCLI command="config:set {{LoginAsCustomerStoreViewLogin.path}} 0"
2525
stepKey="enableLoginAsCustomerAutoDetection"/>
26-
<magentoCLI command="cache:flush config" stepKey="flushCacheBeforeTestRun"/>
2726
<createData entity="_defaultCategory" stepKey="createCategory"/>
2827
<createData entity="SimpleProduct" stepKey="createSimpleProduct">
2928
<requiredEntity createDataKey="createCategory"/>
3029
</createData>
3130
<createData entity="Simple_US_Customer_Assistance_Allowed" stepKey="createCustomer"/>
3231
<actionGroup ref="AdminLoginActionGroup" stepKey="login"/>
32+
<actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindex">
33+
<argument name="indices" value=""/>
34+
</actionGroup>
35+
<actionGroup ref="CliCacheCleanActionGroup" stepKey="cleanInvalidatedCachesAfterSet">
36+
<argument name="tags" value="config full_page"/>
37+
</actionGroup>
3338
</before>
3439
<after>
3540
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
@@ -39,7 +44,12 @@
3944
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
4045
<magentoCLI command="config:set {{LoginAsCustomerConfigDataEnabled.path}} 0"
4146
stepKey="disableLoginAsCustomer"/>
42-
<magentoCLI command="cache:flush config" stepKey="flushCacheAfterTestRun"/>
47+
<actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindexAfter">
48+
<argument name="indices" value=""/>
49+
</actionGroup>
50+
<actionGroup ref="CliCacheCleanActionGroup" stepKey="cleanInvalidatedCachesDefault">
51+
<argument name="tags" value="config full_page"/>
52+
</actionGroup>
4353
</after>
4454

4555
<!-- Verify Login as Customer Login action works correctly from Customer page -->

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
/**
1616
* Sales module base helper
1717
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
18+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1819
*/
1920
class Guest extends \Magento\Framework\App\Helper\AbstractHelper
2021
{
@@ -71,7 +72,7 @@ class Guest extends \Magento\Framework\App\Helper\AbstractHelper
7172
const COOKIE_NAME = 'guest-view';
7273

7374
/**
74-
* Cookie path
75+
* Cookie path value
7576
*/
7677
const COOKIE_PATH = '/';
7778

@@ -151,6 +152,7 @@ public function loadValidOrder(App\RequestInterface $request)
151152
return $this->resultRedirectFactory->create()->setPath('sales/order/history');
152153
}
153154
$post = $request->getPostValue();
155+
$post = filter_var($post, FILTER_CALLBACK, ['options' => 'trim']);
154156
$fromCookie = $this->cookieManager->getCookie(self::COOKIE_NAME);
155157
if (empty($post) && !$fromCookie) {
156158
return $this->resultRedirectFactory->create()->setPath('sales/guest/form');
@@ -224,6 +226,7 @@ private function setGuestViewCookie($cookieValue)
224226
*/
225227
private function loadFromCookie($fromCookie)
226228
{
229+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
227230
$cookieData = explode(':', base64_decode($fromCookie));
228231
$protectCode = isset($cookieData[0]) ? $cookieData[0] : null;
229232
$incrementId = isset($cookieData[1]) ? $cookieData[1] : null;
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="MINOR"/>
17+
<testCaseId value="MC-37449"/>
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: 81 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,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

Comments
 (0)