Skip to content

Commit 99686e2

Browse files
authored
Merge pull request #1395 from magento-folks/MAGETWO-71180
MAGETWO-71180: Customer can't buy Products in Production Mode on French locale
2 parents 903b923 + 1072a7c commit 99686e2

File tree

5 files changed

+119
-10
lines changed

5 files changed

+119
-10
lines changed

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,12 @@ public function __construct(
8686
*/
8787
public function emulateWelcomeBlock($block)
8888
{
89-
$escapedName = $this->_escaper->escapeHtml(
90-
$this->_customerViewHelper->getCustomerName(
91-
$this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId())
92-
),
93-
null
89+
$customerName = $this->_customerViewHelper->getCustomerName(
90+
$this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId())
9491
);
9592

9693
$this->_applyAccountLinksPersistentData();
97-
$welcomeMessage = __('Welcome, %1!', $escapedName)
98-
. ' ' . $this->_layout->getBlock('header.additional')->toHtml();
94+
$welcomeMessage = __('Welcome, %1!', $customerName);
9995
$block->setWelcome($welcomeMessage);
10096
return $this;
10197
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Persistent\Test\Unit\Model;
8+
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
10+
11+
class ObserverTest extends \PHPUnit\Framework\TestCase
12+
{
13+
/**
14+
* @var \Magento\Persistent\Model\Observer
15+
*/
16+
private $observer;
17+
18+
/**
19+
* @var \PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
private $persistentSessionMock;
22+
23+
/**
24+
* @var \PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
private $customerRepositoryMock;
27+
28+
/**
29+
* @var \PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
private $customerViewHelperMock;
32+
33+
/**
34+
* @var \PHPUnit_Framework_MockObject_MockObject
35+
*/
36+
private $escaperMock;
37+
38+
/**
39+
* @var \PHPUnit_Framework_MockObject_MockObject
40+
*/
41+
private $layoutMock;
42+
43+
/**
44+
* @var \PHPUnit_Framework_MockObject_MockObject
45+
*/
46+
private $sessionMock;
47+
48+
protected function setUp()
49+
{
50+
51+
$objectManagerHelper = new ObjectManagerHelper($this);
52+
$this->persistentSessionMock = $this->getMockBuilder(\Magento\Persistent\Helper\Session::class)
53+
->disableOriginalConstructor()
54+
->getMock();
55+
$this->customerRepositoryMock = $this->getMockBuilder(\Magento\Customer\Api\CustomerRepositoryInterface::class)
56+
->disableOriginalConstructor()
57+
->getMock();
58+
$this->customerViewHelperMock = $this->getMockBuilder(\Magento\Customer\Helper\View::class)
59+
->disableOriginalConstructor()
60+
->getMock();
61+
$this->escaperMock = $this->getMockBuilder(\Magento\Framework\Escaper::class)
62+
->disableOriginalConstructor()
63+
->getMock();
64+
$this->layoutMock = $this->getMockBuilder(\Magento\Framework\View\LayoutInterface::class)
65+
->disableOriginalConstructor()
66+
->getMock();
67+
$this->sessionMock = $this->getMockBuilder(\Magento\Persistent\Helper\Session::class)
68+
->disableOriginalConstructor()
69+
->setMethods(['getCustomerId'])
70+
->getMock();
71+
$this->observer = $objectManagerHelper->getObject(
72+
\Magento\Persistent\Model\Observer::class,
73+
[
74+
'persistentSession' => $this->persistentSessionMock,
75+
'customerRepository' => $this->customerRepositoryMock,
76+
'customerViewHelper' => $this->customerViewHelperMock,
77+
'escaper' => $this->escaperMock,
78+
'layout' => $this->layoutMock
79+
]
80+
);
81+
}
82+
83+
public function testEmulateWelcomeBlock()
84+
{
85+
$customerId = 1;
86+
$customerName = 'Test Customer Name';
87+
$welcomeMessage = __('Welcome, %1!', $customerName);
88+
$customerMock = $this->getMockForAbstractClass(\Magento\Customer\Api\Data\CustomerInterface::class);
89+
$block = $this->getMockBuilder(\Magento\Framework\View\Element\AbstractBlock::class)
90+
->disableOriginalConstructor()
91+
->setMethods(['setWelcome'])
92+
->getMock();
93+
$headerAdditionalBlock = $this->getMockBuilder(\Magento\Framework\View\Element\AbstractBlock::class)
94+
->disableOriginalConstructor()
95+
->getMock();
96+
$this->persistentSessionMock->expects($this->once())->method('getSession')->willReturn($this->sessionMock);
97+
$this->sessionMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
98+
$this->customerRepositoryMock
99+
->expects($this->once())
100+
->method('getById')
101+
->with($customerId)->willReturn($customerMock);
102+
$this->customerViewHelperMock->expects($this->once())->method('getCustomerName')->willReturn($customerName);
103+
$this->layoutMock->expects($this->once())
104+
->method('getBlock')
105+
->with('header.additional')
106+
->willReturn($headerAdditionalBlock);
107+
$block->expects($this->once())->method('setWelcome')->with($welcomeMessage);
108+
$this->observer->emulateWelcomeBlock($block);
109+
}
110+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ $welcomeMessage = $block->getWelcome();
1919
</span>
2020
<!-- /ko -->
2121
<!-- ko ifnot: customer().fullname -->
22-
<span data-bind="html:'<?= $block->escapeHtml($welcomeMessage) ?>'"></span>
22+
<span data-bind='html:"<?= $block->escapeHtmlAttr($welcomeMessage) ?>"'></span>
23+
<?= $block->getBlockHtml('header.additional') ?>
2324
<!-- /ko -->
2425
</li>
2526
<script type="text/x-magento-init">

dev/tests/functional/tests/app/Magento/CatalogImportExport/Test/TestCase/ImportProductsTest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<constraint name="Magento\CatalogImportExport\Test\Constraint\AssertProductsInGrid" />
5151
</variation>
5252
<variation name="ImportProductVariation3" ticketId="MAGETWO-47720" summary="Import Simple Product with custom options with Replace Behavior">
53+
<data name="tag" xsi:type="string">stable:no</data>
5354
<data name="import/data/entity" xsi:type="string">Products</data>
5455
<data name="import/data/behavior" xsi:type="string">Replace</data>
5556
<data name="import/data/validation_strategy" xsi:type="string">Stop on Error</data>
@@ -63,6 +64,7 @@
6364
<constraint name="Magento\CatalogImportExport\Test\Constraint\AssertProductsOnStorefront" />
6465
<constraint name="Magento\CatalogImportExport\Test\Constraint\AssertImportedProducts" />
6566
<constraint name="Magento\CatalogImportExport\Test\Constraint\AssertProductsInGrid" />
67+
<data name="issue" xsi:type="string">MAGETWO-71397: Magento\CatalogImportExport\Test\TestCase\ImportProductsTest fails randomly</data>
6668
</variation>
6769
</testCase>
6870
</config>

dev/tests/integration/testsuite/Magento/Persistent/Model/ObserverTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ public function testEmulateWelcomeBlock()
115115
)
116116
)
117117
);
118-
$translation = __('Welcome, %1!', $customerName);
119-
$this->assertStringMatchesFormat('%A' . $translation . '%A', $block->getWelcome());
118+
$translation = __('Welcome, %1!', $customerName)->__toString();
119+
$this->assertStringMatchesFormat('%A' . $translation . '%A', $block->getWelcome()->__toString());
120120
$this->_customerSession->logout();
121121
}
122122
}

0 commit comments

Comments
 (0)