Skip to content

Commit 05ccc44

Browse files
author
Alexander Akimov
authored
Merge pull request #2215 from magento-tsg/2.3-develop-pr4
[TSG] Backporting for 2.3 (pr4) (2.3.0)
2 parents 8f8caf3 + f9365f9 commit 05ccc44

File tree

14 files changed

+327
-101
lines changed

14 files changed

+327
-101
lines changed

app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/hosted-fields.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ define([
6161
},
6262

6363
/**
64-
* @returns {Bool}
64+
* @returns {Boolean}
6565
*/
6666
isVaultEnabled: function () {
6767
return this.vaultEnabler.isVaultEnabled();
@@ -142,11 +142,20 @@ define([
142142
return true;
143143
},
144144

145+
/**
146+
* Returns state of place order button
147+
* @returns {Boolean}
148+
*/
149+
isButtonActive: function () {
150+
return this.isActive() && this.isPlaceOrderActionAllowed();
151+
},
152+
145153
/**
146154
* Trigger order placing
147155
*/
148156
placeOrderClick: function () {
149157
if (this.validateCardType()) {
158+
this.isPlaceOrderActionAllowed(false);
150159
$(this.getSelector('submit')).trigger('click');
151160
}
152161
},

app/code/Magento/Braintree/view/frontend/web/template/payment/form.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@
141141
data-bind="
142142
click: placeOrderClick,
143143
attr: {title: $t('Place Order')},
144-
css: {disabled: !isPlaceOrderActionAllowed()},
145-
enable: isActive()
144+
enable: isButtonActive()
146145
"
147146
disabled>
148147
<span data-bind="i18n: 'Place Order'"></span>

app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Set/Main.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public function getGroupTreeJson()
233233
/* @var $node \Magento\Eav\Model\Entity\Attribute\Group */
234234
foreach ($groups as $node) {
235235
$item = [];
236-
$item['text'] = $node->getAttributeGroupName();
236+
$item['text'] = $this->escapeHtml($node->getAttributeGroupName());
237237
$item['id'] = $node->getAttributeGroupId();
238238
$item['cls'] = 'folder';
239239
$item['allowDrop'] = true;
@@ -280,7 +280,7 @@ public function getAttributeTreeJson()
280280

281281
foreach ($attributes as $child) {
282282
$attr = [
283-
'text' => $child->getAttributeCode(),
283+
'text' => $this->escapeHtml($child->getAttributeCode()),
284284
'id' => $child->getAttributeId(),
285285
'cls' => 'leaf',
286286
'allowDrop' => false,

app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/set/main.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@
315315
},
316316

317317
validateGroupName : function(name, exceptNodeId) {
318-
name = name.strip();
318+
name = name.strip().escapeHTML();
319319
var result = true;
320320
if (name === '') {
321321
result = false;

app/code/Magento/Customer/Model/Plugin/CustomerNotification.php

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Magento\Framework\App\Area;
1313
use Magento\Framework\App\RequestInterface;
1414
use Magento\Framework\App\State;
15+
use Magento\Framework\Exception\NoSuchEntityException;
16+
use Psr\Log\LoggerInterface;
1517

1618
class CustomerNotification
1719
{
@@ -35,24 +37,32 @@ class CustomerNotification
3537
*/
3638
private $state;
3739

40+
/**
41+
* @var LoggerInterface
42+
*/
43+
private $logger;
44+
3845
/**
3946
* Initialize dependencies.
4047
*
4148
* @param Session $session
4249
* @param NotificationStorage $notificationStorage
4350
* @param State $state
4451
* @param CustomerRepositoryInterface $customerRepository
52+
* @param LoggerInterface $logger
4553
*/
4654
public function __construct(
4755
Session $session,
4856
NotificationStorage $notificationStorage,
4957
State $state,
50-
CustomerRepositoryInterface $customerRepository
58+
CustomerRepositoryInterface $customerRepository,
59+
LoggerInterface $logger
5160
) {
5261
$this->session = $session;
5362
$this->notificationStorage = $notificationStorage;
5463
$this->state = $state;
5564
$this->customerRepository = $customerRepository;
65+
$this->logger = $logger;
5666
}
5767

5868
/**
@@ -63,17 +73,23 @@ public function __construct(
6373
*/
6474
public function beforeDispatch(AbstractAction $subject, RequestInterface $request)
6575
{
76+
$customerId = $this->session->getCustomerId();
77+
6678
if ($this->state->getAreaCode() == Area::AREA_FRONTEND && $request->isPost()
6779
&& $this->notificationStorage->isExists(
6880
NotificationStorage::UPDATE_CUSTOMER_SESSION,
69-
$this->session->getCustomerId()
81+
$customerId
7082
)
7183
) {
72-
$customer = $this->customerRepository->getById($this->session->getCustomerId());
73-
$this->session->setCustomerData($customer);
74-
$this->session->setCustomerGroupId($customer->getGroupId());
75-
$this->session->regenerateId();
76-
$this->notificationStorage->remove(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customer->getId());
84+
try {
85+
$customer = $this->customerRepository->getById($customerId);
86+
$this->session->setCustomerData($customer);
87+
$this->session->setCustomerGroupId($customer->getGroupId());
88+
$this->session->regenerateId();
89+
$this->notificationStorage->remove(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customer->getId());
90+
} catch (NoSuchEntityException $e) {
91+
$this->logger->error($e);
92+
}
7793
}
7894
}
7995
}

app/code/Magento/Customer/Model/ResourceModel/CustomerRepository.php

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
namespace Magento\Customer\Model\ResourceModel;
88

99
use Magento\Customer\Api\CustomerMetadataInterface;
10+
use Magento\Customer\Model\Customer\NotificationStorage;
1011
use Magento\Framework\Api\DataObjectHelper;
1112
use Magento\Framework\Api\ImageProcessorInterface;
1213
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
1314
use Magento\Framework\Api\SearchCriteriaInterface;
15+
use Magento\Framework\App\ObjectManager;
1416

1517
/**
1618
* Customer repository.
@@ -88,6 +90,11 @@ class CustomerRepository implements \Magento\Customer\Api\CustomerRepositoryInte
8890
*/
8991
private $collectionProcessor;
9092

93+
/**
94+
* @var NotificationStorage
95+
*/
96+
private $notificationStorage;
97+
9198
/**
9299
* @param \Magento\Customer\Model\CustomerFactory $customerFactory
93100
* @param \Magento\Customer\Model\Data\CustomerSecureFactory $customerSecureFactory
@@ -103,6 +110,7 @@ class CustomerRepository implements \Magento\Customer\Api\CustomerRepositoryInte
103110
* @param ImageProcessorInterface $imageProcessor
104111
* @param \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor
105112
* @param CollectionProcessorInterface $collectionProcessor
113+
* @param NotificationStorage $notificationStorage
106114
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
107115
*/
108116
public function __construct(
@@ -119,7 +127,8 @@ public function __construct(
119127
DataObjectHelper $dataObjectHelper,
120128
ImageProcessorInterface $imageProcessor,
121129
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor,
122-
CollectionProcessorInterface $collectionProcessor = null
130+
CollectionProcessorInterface $collectionProcessor,
131+
NotificationStorage $notificationStorage
123132
) {
124133
$this->customerFactory = $customerFactory;
125134
$this->customerSecureFactory = $customerSecureFactory;
@@ -134,7 +143,8 @@ public function __construct(
134143
$this->dataObjectHelper = $dataObjectHelper;
135144
$this->imageProcessor = $imageProcessor;
136145
$this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor;
137-
$this->collectionProcessor = $collectionProcessor ?: $this->getCollectionProcessor();
146+
$this->collectionProcessor = $collectionProcessor;
147+
$this->notificationStorage = $notificationStorage;
138148
}
139149

140150
/**
@@ -345,6 +355,8 @@ public function deleteById($customerId)
345355
$customerModel = $this->customerRegistry->retrieve($customerId);
346356
$customerModel->delete();
347357
$this->customerRegistry->remove($customerId);
358+
$this->notificationStorage->remove(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customerId);
359+
348360
return true;
349361
}
350362

@@ -370,20 +382,4 @@ protected function addFilterGroupToCollection(
370382
$collection->addFieldToFilter($fields);
371383
}
372384
}
373-
374-
/**
375-
* Retrieve collection processor
376-
*
377-
* @deprecated 100.2.0
378-
* @return CollectionProcessorInterface
379-
*/
380-
private function getCollectionProcessor()
381-
{
382-
if (!$this->collectionProcessor) {
383-
$this->collectionProcessor = \Magento\Framework\App\ObjectManager::getInstance()->get(
384-
'Magento\Eav\Model\Api\SearchCriteria\CollectionProcessor'
385-
);
386-
}
387-
return $this->collectionProcessor;
388-
}
389385
}

app/code/Magento/Customer/Test/Unit/Model/Plugin/CustomerNotificationTest.php

Lines changed: 80 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,82 +5,119 @@
55
*/
66
namespace Magento\Customer\Test\Unit\Model\Plugin;
77

8+
use Magento\Backend\App\AbstractAction;
9+
use Magento\Customer\Api\CustomerRepositoryInterface;
10+
use Magento\Customer\Api\Data\CustomerInterface;
811
use Magento\Customer\Model\Customer\NotificationStorage;
912
use Magento\Customer\Model\Plugin\CustomerNotification;
13+
use Magento\Customer\Model\Session;
14+
use Magento\Framework\App\Area;
15+
use Magento\Framework\App\RequestInterface;
16+
use Magento\Framework\App\State;
17+
use Magento\Framework\Exception\NoSuchEntityException;
18+
use Psr\Log\LoggerInterface;
1019

1120
class CustomerNotificationTest extends \PHPUnit\Framework\TestCase
1221
{
13-
/** @var \Magento\Customer\Model\Session|\PHPUnit_Framework_MockObject_MockObject */
14-
protected $session;
22+
/** @var Session|\PHPUnit_Framework_MockObject_MockObject */
23+
private $sessionMock;
1524

16-
/** @var \Magento\Customer\Model\Customer\NotificationStorage|\PHPUnit_Framework_MockObject_MockObject */
17-
protected $notificationStorage;
25+
/** @var NotificationStorage|\PHPUnit_Framework_MockObject_MockObject */
26+
private $notificationStorageMock;
1827

19-
/** @var \Magento\Customer\Api\CustomerRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject */
20-
protected $customerRepository;
28+
/** @var CustomerRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject */
29+
private $customerRepositoryMock;
2130

22-
/** @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject */
23-
protected $appState;
31+
/** @var State|\PHPUnit_Framework_MockObject_MockObject */
32+
private $appStateMock;
2433

25-
/** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
26-
protected $request;
34+
/** @var RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
35+
private $requestMock;
2736

28-
/** @var \Magento\Backend\App\AbstractAction|\PHPUnit_Framework_MockObject_MockObject */
29-
protected $abstractAction;
37+
/** @var AbstractAction|\PHPUnit_Framework_MockObject_MockObject */
38+
private $abstractActionMock;
39+
40+
/** @var LoggerInterface */
41+
private $loggerMock;
3042

3143
/** @var CustomerNotification */
32-
protected $plugin;
44+
private $plugin;
45+
46+
/** @var int */
47+
private static $customerId = 1;
3348

3449
protected function setUp()
3550
{
36-
$this->session = $this->getMockBuilder(\Magento\Customer\Model\Session::class)
51+
$this->sessionMock = $this->getMockBuilder(Session::class)
3752
->disableOriginalConstructor()
53+
->setMethods(['getCustomerId', 'setCustomerData', 'setCustomerGroupId', 'regenerateId'])
3854
->getMock();
39-
$this->notificationStorage = $this->getMockBuilder(\Magento\Customer\Model\Customer\NotificationStorage::class)
55+
$this->notificationStorageMock = $this->getMockBuilder(NotificationStorage::class)
4056
->disableOriginalConstructor()
57+
->setMethods(['isExists', 'remove'])
4158
->getMock();
42-
$this->customerRepository = $this->getMockBuilder(\Magento\Customer\Api\CustomerRepositoryInterface::class)
59+
$this->customerRepositoryMock = $this->getMockBuilder(CustomerRepositoryInterface::class)
4360
->getMockForAbstractClass();
44-
$this->abstractAction = $this->getMockBuilder(\Magento\Backend\App\AbstractAction::class)
61+
$this->abstractActionMock = $this->getMockBuilder(AbstractAction::class)
4562
->disableOriginalConstructor()
4663
->getMockForAbstractClass();
47-
$this->request = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class)
64+
$this->requestMock = $this->getMockBuilder(RequestInterface::class)
4865
->setMethods(['isPost'])
4966
->getMockForAbstractClass();
50-
$this->appState = $this->getMockBuilder(\Magento\Framework\App\State::class)
51-
->disableOriginalConstructor()->getMock();
67+
$this->appStateMock = $this->getMockBuilder(State::class)
68+
->disableOriginalConstructor()
69+
->setMethods(['getAreaCode'])
70+
->getMock();
71+
72+
$this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
73+
$this->appStateMock->method('getAreaCode')->willReturn(Area::AREA_FRONTEND);
74+
$this->requestMock->method('isPost')->willReturn(true);
75+
$this->sessionMock->method('getCustomerId')->willReturn(self::$customerId);
76+
$this->notificationStorageMock->expects($this->any())
77+
->method('isExists')
78+
->with(NotificationStorage::UPDATE_CUSTOMER_SESSION, self::$customerId)
79+
->willReturn(true);
80+
5281
$this->plugin = new CustomerNotification(
53-
$this->session,
54-
$this->notificationStorage,
55-
$this->appState,
56-
$this->customerRepository
82+
$this->sessionMock,
83+
$this->notificationStorageMock,
84+
$this->appStateMock,
85+
$this->customerRepositoryMock,
86+
$this->loggerMock
5787
);
5888
}
5989

6090
public function testBeforeDispatch()
6191
{
62-
$customerId = 1;
6392
$customerGroupId =1;
64-
$this->appState->expects($this->any())
65-
->method('getAreaCode')
66-
->willReturn(\Magento\Framework\App\Area::AREA_FRONTEND);
67-
$this->request->expects($this->any())->method('isPost')->willReturn(true);
68-
$customerMock = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)
69-
->getMockForAbstractClass();
70-
$customerMock->expects($this->any())->method('getGroupId')->willReturn($customerGroupId);
71-
$this->customerRepository->expects($this->any())
93+
94+
$customerMock = $this->getMockForAbstractClass(CustomerInterface::class);
95+
$customerMock->method('getGroupId')->willReturn($customerGroupId);
96+
$customerMock->method('getId')->willReturn(self::$customerId);
97+
98+
$this->customerRepositoryMock->expects($this->once())
7299
->method('getById')
73-
->with($customerId)
100+
->with(self::$customerId)
74101
->willReturn($customerMock);
75-
$this->session->expects($this->any())->method('getCustomerId')->willReturn($customerId);
76-
$this->session->expects($this->any())->method('setCustomerData')->with($customerMock);
77-
$this->session->expects($this->any())->method('setCustomerGroupId')->with($customerGroupId);
78-
$this->session->expects($this->once())->method('regenerateId');
79-
$this->notificationStorage->expects($this->any())
80-
->method('isExists')
81-
->with(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customerId)
82-
->willReturn(true);
102+
$this->notificationStorageMock->expects($this->once())
103+
->method('remove')
104+
->with(NotificationStorage::UPDATE_CUSTOMER_SESSION, self::$customerId);
105+
106+
$this->sessionMock->expects($this->once())->method('setCustomerData')->with($customerMock);
107+
$this->sessionMock->expects($this->once())->method('setCustomerGroupId')->with($customerGroupId);
108+
$this->sessionMock->expects($this->once())->method('regenerateId');
109+
110+
$this->plugin->beforeDispatch($this->abstractActionMock, $this->requestMock);
111+
}
112+
113+
public function testBeforeDispatchWithNoCustomerFound()
114+
{
115+
$this->customerRepositoryMock->method('getById')
116+
->with(self::$customerId)
117+
->willThrowException(new NoSuchEntityException());
118+
$this->loggerMock->expects($this->once())
119+
->method('error');
83120

84-
$this->plugin->beforeDispatch($this->abstractAction, $this->request);
121+
$this->plugin->beforeDispatch($this->abstractActionMock, $this->requestMock);
85122
}
86123
}

0 commit comments

Comments
 (0)