Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guest print order form fixes #29309

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@
stepKey="enableLoginAsCustomer"/>
<magentoCLI command="config:set {{LoginAsCustomerStoreViewLogin.path}} 0"
stepKey="enableLoginAsCustomerAutoDetection"/>
<magentoCLI command="cache:flush config" stepKey="flushCacheBeforeTestRun"/>
<createData entity="_defaultCategory" stepKey="createCategory"/>
<createData entity="SimpleProduct" stepKey="createSimpleProduct">
<requiredEntity createDataKey="createCategory"/>
</createData>
<createData entity="Simple_US_Customer_Assistance_Allowed" stepKey="createCustomer"/>
<actionGroup ref="AdminLoginActionGroup" stepKey="login"/>
<actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindex">
<argument name="indices" value=""/>
</actionGroup>
<actionGroup ref="CliCacheCleanActionGroup" stepKey="cleanInvalidatedCachesAfterSet">
<argument name="tags" value="config full_page"/>
</actionGroup>
</before>
<after>
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
Expand All @@ -39,7 +44,12 @@
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
<magentoCLI command="config:set {{LoginAsCustomerConfigDataEnabled.path}} 0"
stepKey="disableLoginAsCustomer"/>
<magentoCLI command="cache:flush config" stepKey="flushCacheAfterTestRun"/>
<actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindexAfter">
<argument name="indices" value=""/>
</actionGroup>
<actionGroup ref="CliCacheCleanActionGroup" stepKey="cleanInvalidatedCachesDefault">
<argument name="tags" value="config full_page"/>
</actionGroup>
</after>

<!-- Verify Login as Customer Login action works correctly from Customer page -->
Expand Down
5 changes: 4 additions & 1 deletion app/code/Magento/Sales/Helper/Guest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/**
* Sales module base helper
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
*/
class Guest extends \Magento\Framework\App\Helper\AbstractHelper
{
Expand Down Expand Up @@ -71,7 +72,7 @@ class Guest extends \Magento\Framework\App\Helper\AbstractHelper
const COOKIE_NAME = 'guest-view';

/**
* Cookie path
* Cookie path value
*/
const COOKIE_PATH = '/';

Expand Down Expand Up @@ -151,6 +152,7 @@ public function loadValidOrder(App\RequestInterface $request)
return $this->resultRedirectFactory->create()->setPath('sales/order/history');
}
$post = $request->getPostValue();
$post = filter_var($post, FILTER_CALLBACK, ['options' => 'trim']);
$fromCookie = $this->cookieManager->getCookie(self::COOKIE_NAME);
if (empty($post) && !$fromCookie) {
return $this->resultRedirectFactory->create()->setPath('sales/guest/form');
Expand Down Expand Up @@ -224,6 +226,7 @@ private function setGuestViewCookie($cookieValue)
*/
private function loadFromCookie($fromCookie)
{
// phpcs:ignore Magento2.Functions.DiscouragedFunction
$cookieData = explode(':', base64_decode($fromCookie));
$protectCode = isset($cookieData[0]) ? $cookieData[0] : null;
$incrementId = isset($cookieData[1]) ? $cookieData[1] : null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="StorefrontFillOrdersAndReturnsFormTypeZipActionGroup">
<arguments>
<argument name="orderNumber" type="string"/>
<argument name="customer" type="entity"/>
<argument name="address" type="entity"/>
</arguments>
<fillField selector="{{StorefrontGuestOrderSearchSection.orderId}}" userInput="{{orderNumber}}" stepKey="inputOrderId"/>
<fillField selector="{{StorefrontGuestOrderSearchSection.billingLastName}}" userInput="{{customer.lastname}}" stepKey="inputBillingLastName"/>
<selectOption selector="{{StorefrontGuestOrderSearchSection.findOrderBy}}" userInput="zip" stepKey="selectFindOrderByZip"/>
<fillField selector="{{StorefrontGuestOrderSearchSection.zip}}" userInput="{{address.postcode}}" stepKey="inputZip"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<element name="billingLastName" type="input" selector="#oar-billing-lastname"/>
<element name="findOrderBy" type="select" selector="#quick-search-type-id"/>
<element name="email" type="input" selector="#oar_email"/>
<element name="zip" type="input" selector="#oar_zip"/>
<element name="continue" type="button" selector="//*/span[contains(text(), 'Continue')]"/>
</section>
</sections>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="StorefrontPrintOrderFindByZipGuestTest" extends="StorefrontPrintOrderGuestTest">
<annotations>
<stories value="Print Order"/>
<title value="Print Order from Guest on Frontend using Zip for search"/>
<description value="Print Order from Guest on Frontend"/>
<severity value="MINOR"/>
<testCaseId value="MC-37449"/>
<group value="sales"/>
</annotations>

<remove keyForRemoval="fillOrder"/>

<!-- Fill the form with correspondent Order data using search by Zip -->
<actionGroup ref="StorefrontFillOrdersAndReturnsFormTypeZipActionGroup" stepKey="fillOrderZip" before="clickContinue">
<argument name="orderNumber" value="{$getOrderId}"/>
<argument name="customer" value="$$createCustomer$$"/>
<argument name="address" value="US_Address_TX"/>
</actionGroup>
</test>
</tests>
95 changes: 81 additions & 14 deletions app/code/Magento/Sales/Test/Unit/Helper/GuestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ protected function setUp(): void
->setMethods(['getTotalCount', 'getItems'])
->disableOriginalConstructor()
->getMockForAbstractClass();
$this->searchCriteriaBuilder->method('addFilter')->willReturnSelf();
$resultRedirectFactory =
$this->getMockBuilder(RedirectFactory::class)
->setMethods(['create'])
Expand Down Expand Up @@ -148,29 +147,45 @@ protected function setUp(): void
);
}

public function testLoadValidOrderNotEmptyPost()
/**
* Test load valid order with non empty post data.
*
* @param array $post
* @dataProvider loadValidOrderNotEmptyPostDataProvider
* @throws \Magento\Framework\Exception\InputException
* @throws \Magento\Framework\Stdlib\Cookie\CookieSizeLimitReachedException
* @throws \Magento\Framework\Stdlib\Cookie\FailureToSendException
*/
public function testLoadValidOrderNotEmptyPost($post)
{
$post = [
'oar_order_id' => 1,
'oar_type' => 'email',
'oar_billing_lastname' => 'oar_billing_lastname',
'oar_email' => 'oar_email',
'oar_zip' => 'oar_zip',

];
$incrementId = $post['oar_order_id'];
$protectedCode = 'protectedCode';
$this->sessionMock->expects($this->once())->method('isLoggedIn')->willReturn(false);
$requestMock = $this->createMock(Http::class);
$requestMock->expects($this->once())->method('getPostValue')->willReturn($post);

$this->searchCriteriaBuilder
->expects($this->at(0))
->method('addFilter')
->with('increment_id', trim($incrementId))
->willReturnSelf();

$this->searchCriteriaBuilder
->expects($this->at(1))
->method('addFilter')
->with('store_id', $this->storeModelMock->getId())
->willReturnSelf();

$this->salesOrderMock->expects($this->any())->method('getId')->willReturn($incrementId);

$billingAddressMock = $this->createPartialMock(
Address::class,
['getLastname', 'getEmail']
['getLastname', 'getEmail', 'getPostcode']
);
$billingAddressMock->expects($this->once())->method('getLastname')->willReturn(($post['oar_billing_lastname']));
$billingAddressMock->expects($this->once())->method('getEmail')->willReturn(($post['oar_email']));
$billingAddressMock->expects($this->once())->method('getLastname')
->willReturn(trim($post['oar_billing_lastname']));
$billingAddressMock->expects($this->any())->method('getEmail')->willReturn(trim($post['oar_email']));
$billingAddressMock->expects($this->any())->method('getPostcode')->willReturn(trim($post['oar_zip']));
$this->salesOrderMock->expects($this->once())->method('getBillingAddress')->willReturn($billingAddressMock);
$this->salesOrderMock->expects($this->once())->method('getProtectCode')->willReturn($protectedCode);
$metaDataMock = $this->createMock(PublicCookieMetadata::class);
Expand All @@ -190,17 +205,69 @@ public function testLoadValidOrderNotEmptyPost()
$this->assertTrue($this->guest->loadValidOrder($requestMock));
}

/**
* Load valid order with non empty post data provider.
*
* @return array
*/
public function loadValidOrderNotEmptyPostDataProvider()
{
return [
[
[
'oar_order_id' => '1',
'oar_type' => 'email',
'oar_billing_lastname' => 'White',
'oar_email' => 'test@magento-test.com',
'oar_zip' => '',

]
],
[
[
'oar_order_id' => ' 14 ',
'oar_type' => 'email',
'oar_billing_lastname' => 'Black ',
'oar_email' => ' test1@magento-test.com ',
'oar_zip' => '',
]
],
[
[
'oar_order_id' => ' 14 ',
'oar_type' => 'zip',
'oar_billing_lastname' => 'Black ',
'oar_email' => ' test1@magento-test.com ',
'oar_zip' => '123456 ',
]
]
];
}

public function testLoadValidOrderStoredCookie()
{
$protectedCode = 'protectedCode';
$incrementId = 1;
$incrementId = '1';
$cookieData = $protectedCode . ':' . $incrementId;
$cookieDataHash = base64_encode($cookieData);
$this->sessionMock->expects($this->once())->method('isLoggedIn')->willReturn(false);
$this->cookieManagerMock->expects($this->once())
->method('getCookie')
->with(Guest::COOKIE_NAME)
->willReturn($cookieDataHash);

$this->searchCriteriaBuilder
->expects($this->at(0))
->method('addFilter')
->with('increment_id', trim($incrementId))
->willReturnSelf();

$this->searchCriteriaBuilder
->expects($this->at(1))
->method('addFilter')
->with('store_id', $this->storeModelMock->getId())
->willReturnSelf();

$this->salesOrderMock->expects($this->any())->method('getId')->willReturn($incrementId);
$this->salesOrderMock->expects($this->once())->method('getProtectCode')->willReturn($protectedCode);
$metaDataMock = $this->createMock(PublicCookieMetadata::class);
Expand Down