Skip to content

Commit 68c4836

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-98620' into 2.3-develop-pr20
2 parents 701d1f8 + c998567 commit 68c4836

File tree

6 files changed

+127
-9
lines changed

6 files changed

+127
-9
lines changed

app/code/Magento/Persistent/Model/QuoteManager.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
/**
99
* Class QuoteManager
10+
*
11+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1012
*/
1113
class QuoteManager
1214
{
@@ -87,6 +89,7 @@ public function setGuest($checkQuote = false)
8789
->setCustomerLastname(null)
8890
->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID)
8991
->setIsPersistent(false)
92+
->setCustomerIsGuest(true)
9093
->removeAllAddresses();
9194
//Create guest addresses
9295
$quote->getShippingAddress();

app/code/Magento/Persistent/Observer/CheckExpirePersistentQuoteObserver.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
76
namespace Magento\Persistent\Observer;
87

98
use Magento\Framework\Event\ObserverInterface;
109

10+
/**
11+
* Observer of expired session
12+
*
13+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
14+
*/
1115
class CheckExpirePersistentQuoteObserver implements ObserverInterface
1216
{
1317
/**
@@ -107,8 +111,12 @@ public function execute(\Magento\Framework\Event\Observer $observer)
107111
!$this->_persistentSession->isPersistent() &&
108112
!$this->_customerSession->isLoggedIn() &&
109113
$this->_checkoutSession->getQuoteId() &&
110-
!$this->isRequestFromCheckoutPage($this->request)
114+
!$this->isRequestFromCheckoutPage($this->request) &&
111115
// persistent session does not expire on onepage checkout page
116+
(
117+
$this->_checkoutSession->getQuote()->getIsPersistent() ||
118+
$this->_checkoutSession->getQuote()->getCustomerIsGuest()
119+
)
112120
) {
113121
$this->_eventManager->dispatch('persistent_session_expired');
114122
$this->quoteManager->expire();

app/code/Magento/Persistent/Observer/SetQuotePersistentDataObserver.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
76
namespace Magento\Persistent\Observer;
87

98
use Magento\Framework\Event\ObserverInterface;
109

10+
/**
11+
* Observer for setting "is_persistent" value to quote
12+
*
13+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
14+
*/
1115
class SetQuotePersistentDataObserver implements ObserverInterface
1216
{
1317
/**
@@ -73,8 +77,8 @@ public function execute(\Magento\Framework\Event\Observer $observer)
7377
}
7478

7579
if ((
76-
($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn())
77-
&& !$this->_persistentData->isShoppingCartPersist()
80+
($this->_persistentSession->isPersistent())
81+
&& $this->_persistentData->isShoppingCartPersist()
7882
)
7983
&& $this->quoteManager->isPersistent()
8084
) {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="ShippingQuotePersistedForGuestTest">
11+
<annotations>
12+
<features value="Persistent"/>
13+
<stories value="Guest checkout"/>
14+
<title value="Estimate Shipping and Tax block sections on shipping cart saving correctly for Guest."/>
15+
<description value="Verify that 'Estimate Shipping and Tax' block sections on shipping cart saving correctly for Guest after switching to another page. And check that the shopping cart is cleared after reset persistent cookie."/>
16+
<severity value="CRITICAL"/>
17+
<testCaseId value="MAGETWO-99025"/>
18+
<useCaseId value="MAGETWO-98620"/>
19+
<group value="persistent"/>
20+
</annotations>
21+
<before>
22+
<!--Enabled The Persistent Shopping Cart feature -->
23+
<createData entity="PersistentConfigEnabled" stepKey="enablePersistent"/>
24+
<createData entity="PersistentLogoutClearDisable" stepKey="persistentLogoutClearDisable"/>
25+
<!--Create simple product-->
26+
<createData entity="SimpleProduct2" stepKey="createProduct">
27+
<field key="price">150</field>
28+
</createData>
29+
<!--Create customer-->
30+
<createData entity="Simple_US_Customer" stepKey="createCustomer">
31+
<field key="firstname">John1</field>
32+
<field key="lastname">Doe1</field>
33+
</createData>
34+
</before>
35+
<after>
36+
<!--Revert persistent configuration to default-->
37+
<createData entity="PersistentConfigDefault" stepKey="setDefaultPersistentState"/>
38+
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
39+
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
40+
<actionGroup ref="logout" stepKey="logout"/>
41+
</after>
42+
<!--Step 1: Login as a Customer with remember me checked-->
43+
<actionGroup ref="CustomerLoginOnStorefrontWithRememberMeChecked" stepKey="loginToStorefrontAccountWithRememberMeChecked">
44+
<argument name="Customer" value="$$createCustomer$$"/>
45+
</actionGroup>
46+
<!--Step 2: Open the Product Page and add the product to shopping cart-->
47+
<amOnPage url="{{StorefrontProductPage.url($$createProduct.custom_attributes[url_key]$$)}}" stepKey="navigateToProductPageAsLoggedUser"/>
48+
<actionGroup ref="addToCartFromStorefrontProductPage" stepKey="addProductToCartAsLoggedUser">
49+
<argument name="productName" value="$$createProduct.name$$"/>
50+
</actionGroup>
51+
<!--Step 3: Log out, reset persistent cookie and go to homepage-->
52+
<amOnPage url="{{StorefrontCustomerSignOutPage.url}}" stepKey="signOut"/>
53+
<waitForLoadingMaskToDisappear stepKey="waitSignOutPage"/>
54+
<resetCookie userInput="persistent_shopping_cart" stepKey="resetPersistentCookie"/>
55+
<amOnPage url="{{StorefrontHomePage.url}}" stepKey="amOnHomePageAfterResetPersistentCookie"/>
56+
<waitForPageLoad stepKey="waitHomePageLoadAfterResetCookie"/>
57+
<!--Check that the minicart is empty-->
58+
<actionGroup ref="assertMiniCartEmpty" after="waitHomePageLoadAfterResetCookie" stepKey="seeMinicartEmpty"/>
59+
<!--Step 4: Add the product to shopping cart and open cart-->
60+
<amOnPage url="{{StorefrontProductPage.url($$createProduct.custom_attributes[url_key]$$)}}" stepKey="navigateToProductPageAsGuestUser"/>
61+
<actionGroup ref="addToCartFromStorefrontProductPage" stepKey="addProductToCartAsGuestUser">
62+
<argument name="productName" value="$$createProduct.name$$"/>
63+
</actionGroup>
64+
<actionGroup ref="clickViewAndEditCartFromMiniCart" stepKey="goToShoppingCartBeforeChangeShippingAndTaxSection"/>
65+
<!--Step 5: Open Estimate Shipping and Tax block and fill the sections-->
66+
<conditionalClick selector="{{CheckoutCartSummarySection.estimateShippingAndTax}}" dependentSelector="{{CheckoutCartSummarySection.country}}" visible="false" stepKey="expandEstimateShippingAndTax" />
67+
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMask"/>
68+
<selectOption selector="{{CheckoutCartSummarySection.country}}" userInput="{{US_Address_CA.country}}" stepKey="selectUSCountry"/>
69+
<selectOption selector="{{CheckoutCartSummarySection.stateProvince}}" userInput="{{US_Address_CA.state}}" stepKey="selectCaliforniaRegion"/>
70+
<fillField selector="{{CheckoutCartSummarySection.postcode}}" userInput="{{US_Address_CA.postcode}}" stepKey="inputPostCode"/>
71+
<!--Step 6: Go to Homepage-->
72+
<amOnPage url="{{StorefrontHomePage.url}}" stepKey="goToHomePageAfterChangingShippingAndTaxSection"/>
73+
<!--Step 7: Go to shopping cart and check "Estimate Shipping and Tax" fields values are saved-->
74+
<actionGroup ref="clickViewAndEditCartFromMiniCart" after="goToHomePageAfterChangingShippingAndTaxSection" stepKey="goToShoppingCartAfterChangingShippingAndTaxSection"/>
75+
<conditionalClick selector="{{CheckoutCartSummarySection.estimateShippingAndTax}}" dependentSelector="{{CheckoutCartSummarySection.country}}" visible="false" stepKey="expandEstimateShippingAndTaxAfterChanging" />
76+
<seeOptionIsSelected selector="{{CheckoutCartSummarySection.country}}" userInput="{{US_Address_CA.country}}" stepKey="checkCustomerCountry" />
77+
<seeOptionIsSelected selector="{{CheckoutCartSummarySection.stateProvince}}" userInput="{{US_Address_CA.state}}" stepKey="checkCustomerRegion" />
78+
<grabValueFrom selector="{{CheckoutCartSummarySection.postcode}}" stepKey="grabTextPostCode"/>
79+
<assertEquals message="Customer postcode is invalid" stepKey="checkCustomerPostcode">
80+
<expectedResult type="string">{{US_Address_CA.postcode}}</expectedResult>
81+
<actualResult type="variable">grabTextPostCode</actualResult>
82+
</assertEquals>
83+
</test>
84+
</tests>

app/code/Magento/Persistent/Test/Unit/Observer/CheckExpirePersistentQuoteObserverTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
76

87
namespace Magento\Persistent\Test\Unit\Observer;
98

9+
use Magento\Quote\Model\Quote;
10+
11+
/**
12+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
13+
*/
1014
class CheckExpirePersistentQuoteObserverTest extends \PHPUnit\Framework\TestCase
1115
{
1216
/**
@@ -54,6 +58,11 @@ class CheckExpirePersistentQuoteObserverTest extends \PHPUnit\Framework\TestCase
5458
*/
5559
private $requestMock;
5660

61+
/**
62+
* @var \PHPUnit_Framework_MockObject_MockObject|Quote
63+
*/
64+
private $quoteMock;
65+
5766
/**
5867
* @inheritdoc
5968
*/
@@ -83,6 +92,10 @@ protected function setUp()
8392
$this->checkoutSessionMock,
8493
$this->requestMock
8594
);
95+
$this->quoteMock = $this->getMockBuilder(Quote::class)
96+
->setMethods(['getCustomerIsGuest', 'getIsPersistent'])
97+
->disableOriginalConstructor()
98+
->getMock();
8699
}
87100

88101
public function testExecuteWhenCanNotApplyPersistentData()
@@ -133,6 +146,11 @@ public function testExecuteWhenPersistentIsEnabled(
133146
->willReturn(true);
134147
$this->persistentHelperMock->expects($this->once())->method('isEnabled')->willReturn(true);
135148
$this->sessionMock->expects($this->once())->method('isPersistent')->willReturn(false);
149+
$this->checkoutSessionMock
150+
->method('getQuote')
151+
->willReturn($this->quoteMock);
152+
$this->quoteMock->method('getCustomerIsGuest')->willReturn(true);
153+
$this->quoteMock->method('getIsPersistent')->willReturn(true);
136154
$this->customerSessionMock
137155
->expects($this->atLeastOnce())
138156
->method('isLoggedIn')

app/code/Magento/Persistent/Test/Unit/Observer/SetQuotePersistentDataObserverTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
namespace Magento\Persistent\Test\Unit\Observer;
99

10+
/**
11+
* Observer test for setting "is_persistent" value to quote
12+
*/
1013
class SetQuotePersistentDataObserverTest extends \PHPUnit\Framework\TestCase
1114
{
1215
/**
@@ -83,7 +86,6 @@ public function testExecuteWhenQuoteNotExist()
8386
->method('getEvent')
8487
->will($this->returnValue($this->eventManagerMock));
8588
$this->eventManagerMock->expects($this->once())->method('getQuote');
86-
$this->customerSessionMock->expects($this->never())->method('isLoggedIn');
8789
$this->model->execute($this->observerMock);
8890
}
8991

@@ -98,8 +100,7 @@ public function testExecuteWhenSessionIsPersistent()
98100
->expects($this->once())
99101
->method('getQuote')
100102
->will($this->returnValue($this->quoteMock));
101-
$this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false));
102-
$this->helperMock->expects($this->once())->method('isShoppingCartPersist')->will($this->returnValue(false));
103+
$this->helperMock->expects($this->once())->method('isShoppingCartPersist')->will($this->returnValue(true));
103104
$this->quoteManagerMock->expects($this->once())->method('isPersistent')->will($this->returnValue(true));
104105
$this->quoteMock->expects($this->once())->method('setIsPersistent')->with(true);
105106
$this->model->execute($this->observerMock);

0 commit comments

Comments
 (0)