Skip to content

Commit 78b6e7b

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-97278' into 2.3-develop-pr39
2 parents cc0c184 + f1a44ab commit 78b6e7b

File tree

25 files changed

+541
-281
lines changed

25 files changed

+541
-281
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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="CustomerLogoutStorefrontByMenuItemsActionGroup">
12+
<conditionalClick selector="{{StorefrontPanelHeaderSection.customerWelcome}}"
13+
dependentSelector="{{StorefrontPanelHeaderSection.customerWelcomeMenu}}"
14+
visible="false"
15+
stepKey="clickHeaderCustomerMenuButton" />
16+
<click selector="{{StorefrontPanelHeaderSection.customerLogoutLink}}" stepKey="clickSignOutButton" />
17+
</actionGroup>
18+
</actionGroups>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/PageObject.xsd">
10+
<page name="StorefrontCustomerLogoutSuccessPage" url="customer/account/logoutSuccess/" area="storefront" module="Magento_Customer"/>
11+
</pages>

app/code/Magento/Customer/Test/Mftf/Section/StorefrontPanelHeaderSection.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@
1212
<element name="WelcomeMessage" type="text" selector=".greet.welcome span"/>
1313
<element name="createAnAccountLink" type="select" selector=".panel.header li:nth-child(3)" timeout="30"/>
1414
<element name="notYouLink" type="button" selector=".greet.welcome span a"/>
15+
<element name="customerWelcome" type="text" selector=".panel.header .customer-welcome"/>
16+
<element name="customerWelcomeMenu" type="text" selector=".panel.header .customer-welcome .customer-menu"/>
17+
<element name="customerLogoutLink" type="text" selector=".panel.header .customer-welcome .customer-menu .authorization-link a" timeout="30"/>
1518
</section>
1619
</sections>

app/code/Magento/Persistent/Block/Header/Additional.php

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
*/
66
namespace Magento\Persistent\Block\Header;
77

8+
use Magento\Framework\App\ObjectManager;
9+
use Magento\Framework\Serialize\Serializer\Json;
10+
use Magento\Persistent\Helper\Data;
11+
812
/**
913
* Remember Me block
1014
*
@@ -30,27 +34,46 @@ class Additional extends \Magento\Framework\View\Element\Html\Link
3034
protected $customerRepository;
3135

3236
/**
33-
* Constructor
34-
*
37+
* @var string
38+
*/
39+
protected $_template = 'Magento_Persistent::additional.phtml';
40+
41+
/**
42+
* @var Json
43+
*/
44+
private $jsonSerializer;
45+
46+
/**
47+
* @var Data
48+
*/
49+
private $persistentHelper;
50+
51+
/**
3552
* @param \Magento\Framework\View\Element\Template\Context $context
3653
* @param \Magento\Customer\Helper\View $customerViewHelper
3754
* @param \Magento\Persistent\Helper\Session $persistentSessionHelper
3855
* @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository
3956
* @param array $data
57+
* @param Json|null $jsonSerializer
58+
* @param Data|null $persistentHelper
4059
*/
4160
public function __construct(
4261
\Magento\Framework\View\Element\Template\Context $context,
4362
\Magento\Customer\Helper\View $customerViewHelper,
4463
\Magento\Persistent\Helper\Session $persistentSessionHelper,
4564
\Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
46-
array $data = []
65+
array $data = [],
66+
Json $jsonSerializer = null,
67+
Data $persistentHelper = null
4768
) {
4869
$this->isScopePrivate = true;
4970
$this->_customerViewHelper = $customerViewHelper;
5071
$this->_persistentSessionHelper = $persistentSessionHelper;
5172
$this->customerRepository = $customerRepository;
5273
parent::__construct($context, $data);
5374
$this->_isScopePrivate = true;
75+
$this->jsonSerializer = $jsonSerializer ?: ObjectManager::getInstance()->get(Json::class);
76+
$this->persistentHelper = $persistentHelper ?: ObjectManager::getInstance()->get(Data::class);
5477
}
5578

5679
/**
@@ -64,17 +87,26 @@ public function getHref()
6487
}
6588

6689
/**
67-
* Render additional header html
90+
* Get customer id.
6891
*
69-
* @return string
92+
* @return int
7093
*/
71-
protected function _toHtml()
94+
public function getCustomerId(): int
7295
{
73-
if ($this->_persistentSessionHelper->getSession()->getCustomerId()) {
74-
return '<span><a ' . $this->getLinkAttributes() . ' >' . __('Not you?')
75-
. '</a></span>';
76-
}
96+
return $this->_persistentSessionHelper->getSession()->getCustomerId();
97+
}
7798

78-
return '';
99+
/**
100+
* Get persistent config.
101+
*
102+
* @return string
103+
*/
104+
public function getConfig(): string
105+
{
106+
return $this->jsonSerializer->serialize(
107+
[
108+
'expirationLifetime' => $this->persistentHelper->getLifeTime(),
109+
]
110+
);
79111
}
80112
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Persistent\CustomerData;
9+
10+
use Magento\Customer\Api\CustomerRepositoryInterface;
11+
use Magento\Customer\CustomerData\SectionSourceInterface;
12+
use Magento\Customer\Helper\View;
13+
use Magento\Persistent\Helper\Session;
14+
15+
/**
16+
* Customer persistent section
17+
*/
18+
class Persistent implements SectionSourceInterface
19+
{
20+
/**
21+
* @var Session
22+
*/
23+
private $persistentSession;
24+
25+
/**
26+
* @var View
27+
*/
28+
private $customerViewHelper;
29+
30+
/**
31+
* @var CustomerRepositoryInterface
32+
*/
33+
private $customerRepository;
34+
35+
/**
36+
* @param Session $persistentSession
37+
* @param View $customerViewHelper
38+
* @param CustomerRepositoryInterface $customerRepository
39+
*/
40+
public function __construct(
41+
Session $persistentSession,
42+
View $customerViewHelper,
43+
CustomerRepositoryInterface $customerRepository
44+
) {
45+
$this->persistentSession = $persistentSession;
46+
$this->customerViewHelper = $customerViewHelper;
47+
$this->customerRepository = $customerRepository;
48+
}
49+
50+
/**
51+
* Get data.
52+
*
53+
* @return array
54+
*/
55+
public function getSectionData(): array
56+
{
57+
if (!$this->persistentSession->isPersistent()) {
58+
return [];
59+
}
60+
61+
$customerId = $this->persistentSession->getSession()->getCustomerId();
62+
if (!$customerId) {
63+
return [];
64+
}
65+
66+
$customer = $this->customerRepository->getById($customerId);
67+
68+
return [
69+
'fullname' => $this->customerViewHelper->getCustomerName($customer),
70+
];
71+
}
72+
}

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,8 @@ public function __construct(
8686
*/
8787
public function emulateWelcomeBlock($block)
8888
{
89-
$customerName = $this->_customerViewHelper->getCustomerName(
90-
$this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId())
91-
);
89+
$block->setWelcome('&nbsp;');
9290

93-
$this->_applyAccountLinksPersistentData();
94-
$welcomeMessage = __('Welcome, %1!', $customerName);
95-
$block->setWelcome($welcomeMessage);
9691
return $this;
9792
}
9893

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Persistent\Model\Plugin;
9+
10+
/**
11+
* Plugin for Magento\Framework\App\Http\Context to create new page cache variation for persistent session.
12+
*/
13+
class PersistentCustomerContext
14+
{
15+
/**
16+
* Persistent session.
17+
*
18+
* @var \Magento\Persistent\Helper\Session
19+
*/
20+
private $persistentSession;
21+
22+
/**
23+
* @param \Magento\Persistent\Helper\Session $persistentSession
24+
*/
25+
public function __construct(
26+
\Magento\Persistent\Helper\Session $persistentSession
27+
) {
28+
$this->persistentSession = $persistentSession;
29+
}
30+
31+
/**
32+
* Sets appropriate header if customer session is persistent.
33+
*
34+
* @param \Magento\Framework\App\Http\Context $subject
35+
* @return mixed
36+
*/
37+
public function beforeGetVaryString(\Magento\Framework\App\Http\Context $subject)
38+
{
39+
if ($this->persistentSession->isPersistent()) {
40+
$subject->setValue('PERSISTENT', 1, 0);
41+
}
42+
}
43+
}
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="CustomerLoginOnStorefrontWithRememberMeChecked" extends="LoginToStorefrontActionGroup">
12+
<checkOption selector="{{StorefrontCustomerSignInFormSection.rememberMe}}"
13+
before="clickSignInAccountButton"
14+
stepKey="checkRememberMe"/>
15+
</actionGroup>
16+
17+
<actionGroup name="CustomerLoginOnStorefrontWithRememberMeUnChecked" extends="LoginToStorefrontActionGroup">
18+
<uncheckOption selector="{{StorefrontCustomerSignInFormSection.rememberMe}}"
19+
before="clickSignInAccountButton"
20+
stepKey="unCheckRememberMe"/>
21+
</actionGroup>
22+
</actionGroups>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
11+
<section name="StorefrontCustomerSignInFormSection">
12+
<element name="rememberMe" type="checkbox" selector="[name='persistent_remember_me']"/>
13+
</section>
14+
</sections>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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="StorefrontCorrectWelcomeMessageAfterCustomerIsLoggedOutTest">
12+
<annotations>
13+
<features value="Persistent"/>
14+
<stories value="MAGETWO-97278 - Incorrect use of cookies for customer"/>
15+
<title value="Checking welcome message for persistent customer after logout"/>
16+
<description value="Checking welcome message for persistent customer after logout"/>
17+
<severity value="MAJOR"/>
18+
<testCaseId value="MC-10800"/>
19+
<group value="persistent"/>
20+
<group value="customer"/>
21+
</annotations>
22+
<before>
23+
<!--Enable Persistence-->
24+
<createData entity="PersistentConfigEnabled" stepKey="enablePersistent"/>
25+
<createData entity="PersistentLogoutClearDisable" stepKey="persistentLogoutClearDisable"/>
26+
27+
<!--Create customers-->
28+
<createData entity="Simple_US_Customer" stepKey="createCustomer"/>
29+
<createData entity="Simple_US_Customer" stepKey="createCustomerForPersistent">
30+
<field key="firstname">John1</field>
31+
<field key="lastname">Doe1</field>
32+
</createData>
33+
</before>
34+
<after>
35+
<!--Roll back configuration-->
36+
<createData entity="PersistentConfigDefault" stepKey="setDefaultPersistentState"/>
37+
<createData entity="PersistentLogoutClearEnabled" stepKey="persistentLogoutClearEnabled"/>
38+
39+
<!-- Logout customer on Storefront-->
40+
<actionGroup ref="StorefrontCustomerLogoutActionGroup" stepKey="customerLogoutStorefront"/>
41+
<!--Delete customers-->
42+
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
43+
<deleteData createDataKey="createCustomerForPersistent" stepKey="deleteCustomerForPersistent"/>
44+
</after>
45+
<!--Login as a Customer with remember me unchecked-->
46+
<actionGroup ref="CustomerLoginOnStorefrontWithRememberMeUnChecked" stepKey="loginToStorefrontAccountWithRememberMeUnchecked">
47+
<argument name="Customer" value="$$createCustomer$$"/>
48+
</actionGroup>
49+
50+
<!--Check customer name and last name in welcome message-->
51+
<seeInCurrentUrl url="{{StorefrontCustomerDashboardPage.url}}" stepKey="seeCustomerAccountPageUrl"/>
52+
<see userInput="Welcome, $$createCustomer.firstname$$ $$createCustomer.lastname$$!"
53+
selector="{{StorefrontHeaderSection.welcomeMessage}}"
54+
stepKey="seeLoggedInCustomerWelcomeMessage"/>
55+
<!--Logout and check default welcome message-->
56+
<actionGroup ref="CustomerLogoutStorefrontByMenuItemsActionGroup" stepKey="storefrontCustomerLogout"/>
57+
<seeInCurrentUrl url="{{StorefrontCustomerLogoutSuccessPage.url}}" wait="5" stepKey="seeCustomerSignOutPageUrl"/>
58+
<see userInput="Default welcome msg!"
59+
selector="{{StorefrontHeaderSection.welcomeMessage}}"
60+
stepKey="seeDefaultWelcomeMessage"/>
61+
62+
<!--Login as a Customer with remember me checked-->
63+
<actionGroup ref="CustomerLoginOnStorefrontWithRememberMeChecked" stepKey="loginToStorefrontAccountWithRememberMeChecked">
64+
<argument name="Customer" value="$$createCustomerForPersistent$$"/>
65+
</actionGroup>
66+
<!--Check customer name and last name in welcome message-->
67+
<seeInCurrentUrl url="{{StorefrontCustomerDashboardPage.url}}" stepKey="seeCustomerAccountPageUrl1"/>
68+
<see userInput="Welcome, $$createCustomerForPersistent.firstname$$ $$createCustomerForPersistent.lastname$$!"
69+
selector="{{StorefrontHeaderSection.welcomeMessage}}"
70+
stepKey="seeLoggedInCustomerWelcomeMessage1"/>
71+
72+
<!--Logout and check persistent customer welcome message-->
73+
<actionGroup ref="CustomerLogoutStorefrontByMenuItemsActionGroup" stepKey="storefrontCustomerLogout1"/>
74+
<seeInCurrentUrl url="{{StorefrontCustomerLogoutSuccessPage.url}}" wait="5" stepKey="seeCustomerSignOutPageUrl1"/>
75+
<see userInput="Welcome, $$createCustomerForPersistent.firstname$$ $$createCustomerForPersistent.lastname$$! Not you?"
76+
selector="{{StorefrontHeaderSection.welcomeMessage}}"
77+
stepKey="seePersistentWelcomeMessage"/>
78+
</test>
79+
</tests>

0 commit comments

Comments
 (0)