Skip to content

Commit c333b43

Browse files
committed
MAGETWO-45665: There is no ability to sign out if Clear Persistence on Log Out = No
1 parent 8720b96 commit c333b43

File tree

5 files changed

+163
-1
lines changed

5 files changed

+163
-1
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Persistent\Model\Plugin;
7+
8+
class CustomerData
9+
{
10+
/**
11+
* Persistent data
12+
*
13+
* @var \Magento\Persistent\Helper\Data
14+
*/
15+
protected $persistentData;
16+
17+
/**
18+
* Customer session
19+
*
20+
* @var \Magento\Customer\Model\Session
21+
*/
22+
protected $customerSession;
23+
24+
/**
25+
* Persistent session
26+
*
27+
* @var \Magento\Persistent\Helper\Session
28+
*/
29+
protected $persistentSession;
30+
31+
/**
32+
* CustomerData constructor.
33+
*
34+
* @param \Magento\Persistent\Helper\Data $persistentData
35+
* @param \Magento\Customer\Model\Session $customerSession
36+
* @param \Magento\Persistent\Helper\Session $persistentSession
37+
*/
38+
public function __construct(
39+
\Magento\Persistent\Helper\Data $persistentData,
40+
\Magento\Customer\Model\Session $customerSession,
41+
\Magento\Persistent\Helper\Session $persistentSession
42+
) {
43+
$this->persistentData = $persistentData;
44+
$this->customerSession = $customerSession;
45+
$this->persistentSession = $persistentSession;
46+
}
47+
48+
/**
49+
* Reset quote reward point amount
50+
*
51+
* @param \Magento\Customer\CustomerData\Customer $subject
52+
* @param \Closure $proceed
53+
*
54+
* @return array
55+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
56+
*/
57+
public function aroundGetSectionData(
58+
\Magento\Customer\CustomerData\Customer $subject,
59+
\Closure $proceed
60+
) {
61+
/** unset customer first name */
62+
if (
63+
!$this->customerSession->isLoggedIn()
64+
&& $this->persistentData->isEnabled()
65+
&& $this->persistentSession->isPersistent()
66+
) {
67+
return [];
68+
}
69+
return $proceed();
70+
}
71+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Persistent\Test\Unit\Model\Plugin;
8+
9+
class CustomerDataTest extends \PHPUnit_Framework_TestCase
10+
{
11+
/**
12+
* @var \Magento\Persistent\Model\Plugin\CustomerData
13+
*/
14+
protected $plugin;
15+
16+
/**
17+
* @var \PHPUnit_Framework_MockObject_MockObject
18+
*/
19+
protected $helperMock;
20+
21+
/**
22+
* @var \PHPUnit_Framework_MockObject_MockObject
23+
*/
24+
protected $customerSessionMock;
25+
26+
/**
27+
* @var \PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
protected $persistentSessionMock;
30+
31+
/**
32+
* @var \PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
protected $subjectMock;
35+
36+
protected function setUp()
37+
{
38+
$this->helperMock = $this->getMock('Magento\Persistent\Helper\Data', [], [], '', false);
39+
$this->customerSessionMock = $this->getMock('Magento\Customer\Model\Session', [], [], '', false);
40+
$this->persistentSessionMock = $this->getMock('Magento\Persistent\Helper\Session', [], [], '', false);
41+
$this->subjectMock = $this->getMock('\Magento\Customer\CustomerData\Customer', [], [], '', false);
42+
$this->plugin = new \Magento\Persistent\Model\Plugin\CustomerData(
43+
$this->helperMock,
44+
$this->customerSessionMock,
45+
$this->persistentSessionMock
46+
);
47+
}
48+
49+
public function testAroundGetSectionDataForPersistentSession()
50+
{
51+
$result = 'result';
52+
$proceed = function () use ($result) {
53+
return $result;
54+
};
55+
56+
$this->customerSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(false);
57+
$this->helperMock->expects($this->once())->method('isEnabled')->willReturn(true);
58+
$this->persistentSessionMock->expects($this->once())->method('isPersistent')->willReturn(true);
59+
60+
$this->assertEquals([], $this->plugin->aroundGetSectionData($this->subjectMock, $proceed));
61+
}
62+
63+
64+
public function testAroundGetSectionData()
65+
{
66+
$result = 'result';
67+
$proceed = function () use ($result) {
68+
return $result;
69+
};
70+
71+
$this->customerSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(false);
72+
$this->helperMock->expects($this->once())->method('isEnabled')->willReturn(true);
73+
$this->persistentSessionMock->expects($this->once())->method('isPersistent')->willReturn(false);
74+
75+
$this->assertEquals($result, $this->plugin->aroundGetSectionData($this->subjectMock, $proceed));
76+
}
77+
}

app/code/Magento/Persistent/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@
99
<type name="Magento\Quote\Model\AddressAdditionalDataProcessor">
1010
<plugin name="persistent_remember_me_checkbox_processor" type="Magento\Persistent\Model\Checkout\AddressDataProcessorPlugin" />
1111
</type>
12+
<type name="Magento\Customer\CustomerData\Customer">
13+
<plugin name="section_data" type="Magento\Persistent\Model\Plugin\CustomerData" />
14+
</type>
1215
</config>

app/code/Magento/Persistent/etc/persistent.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Persistent:etc/./persistent.xsd">
99
<instances>
1010
<blocks>
11+
<reference id="welcome">
12+
<name_in_layout>header</name_in_layout>
13+
<class>Magento\Persistent\Model\Observer</class>
14+
<method>emulateWelcomeBlock</method>
15+
<block_type>Magento\Theme\Block\Html\Header</block_type>
16+
</reference>
1117
<reference id="top_links">
1218
<name_in_layout>top.links</name_in_layout>
1319
<class>Magento\Persistent\Model\Observer</class>

app/code/Magento/Theme/view/frontend/templates/html/header.phtml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ $welcomeMessage = $block->getWelcome();
1414
<?php switch ($block->getShowPart()):
1515
case 'welcome': ?>
1616
<li class="greet welcome" data-bind="scope: 'customer'">
17-
<span data-bind="text: customer().fullname ? $t('Welcome, %1!').replace('%1', customer().fullname) : '<?=$block->escapeHtml($welcomeMessage) ?>'"></span>
17+
<!-- ko if: customer().fullname -->
18+
<span data-bind="text: $t('Welcome, %1!').replace('%1', customer().fullname)"></span>
19+
<!-- /ko -->
20+
<!-- ko ifnot: customer().fullname -->
21+
<span data-bind="html:'<?=$block->escapeHtml($welcomeMessage) ?>'"></span>
22+
<!-- /ko -->
1823
</li>
1924
<script type="text/x-magento-init">
2025
{

0 commit comments

Comments
 (0)