Skip to content

Commit e03c5ae

Browse files
author
Yushkin, Dmytro
committed
Merge pull request #478 from magento-mpi/MPI-regression
[MPI] Bugfixes
2 parents 137733b + 0e31742 commit e03c5ae

File tree

44 files changed

+523
-183
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+523
-183
lines changed

app/code/Magento/AdvancedPricingImportExport/Model/Export/AdvancedPricing.php

-3
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,8 @@ class AdvancedPricing extends \Magento\CatalogImportExport\Model\Export\Product
9595
* @param \Magento\CatalogImportExport\Model\Export\Product\Type\Factory $_typeFactory
9696
* @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
9797
* @param \Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer
98-
* @param \Magento\Framework\Model\Entity\MetadataPool $metadataPool
9998
* @param ImportProduct\StoreResolver $storeResolver
10099
* @param \Magento\Customer\Api\GroupRepositoryInterface $groupRepository
101-
* @param \Magento\Framework\Model\Entity\MetadataPool $metadataPool
102100
* @throws \Magento\Framework\Exception\LocalizedException
103101
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
104102
*/
@@ -119,7 +117,6 @@ public function __construct(
119117
\Magento\CatalogImportExport\Model\Export\Product\Type\Factory $_typeFactory,
120118
\Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider,
121119
\Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer,
122-
\Magento\Framework\Model\Entity\MetadataPool $metadataPool,
123120
\Magento\CatalogImportExport\Model\Import\Product\StoreResolver $storeResolver,
124121
\Magento\Customer\Api\GroupRepositoryInterface $groupRepository
125122
) {

app/code/Magento/AdvancedPricingImportExport/Test/Unit/Model/Export/AdvancedPricingTest.php

-13
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,6 @@ class AdvancedPricingTest extends \PHPUnit_Framework_TestCase
107107
*/
108108
protected $groupRepository;
109109

110-
/**
111-
* @var \Magento\Framework\Model\Entity\MetadataPool|\PHPUnit_Framework_MockObject_MockObject
112-
*/
113-
protected $metadataPool;
114-
115110
/**
116111
* @var \Magento\ImportExport\Model\Export\Adapter\AbstractAdapter| \PHPUnit_Framework_MockObject_MockObject
117112
*/
@@ -290,13 +285,6 @@ protected function setUp()
290285
'',
291286
false
292287
);
293-
$this->metadataPool = $this->getMock(
294-
'\Magento\Framework\Model\Entity\MetadataPool',
295-
[],
296-
[],
297-
'',
298-
false
299-
);
300288
$this->writer = $this->getMock(
301289
'Magento\ImportExport\Model\Export\Adapter\AbstractAdapter',
302290
[
@@ -355,7 +343,6 @@ protected function setUp()
355343
$this->typeFactory,
356344
$this->linkTypeProvider,
357345
$this->rowCustomizer,
358-
$this->metadataPool,
359346
$this->storeResolver,
360347
$this->groupRepository
361348
);

app/code/Magento/Authorizenet/Controller/Directpost/Payment/Place.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ protected function placeCheckoutOrder()
127127
);
128128
} catch (\Exception $exception) {
129129
$result->setData('error', true);
130-
$result->setData('error_messages', __('Cannot place order.'));
130+
$result->setData('error_messages', __('Unable to place order. Please try again later.'));
131131
}
132132
if ($response instanceof Http) {
133133
$response->representJson($this->jsonHelper->jsonEncode($result));

app/code/Magento/Authorizenet/Controller/Directpost/Payment/Redirect.php

+37-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,20 @@
66
*/
77
namespace Magento\Authorizenet\Controller\Directpost\Payment;
88

9+
use Magento\Framework\App\ObjectManager;
910
use Magento\Payment\Block\Transparent\Iframe;
11+
use Magento\Framework\Escaper;
1012

13+
/**
14+
* Class Redirect
15+
*/
1116
class Redirect extends \Magento\Authorizenet\Controller\Directpost\Payment
1217
{
18+
/**
19+
* @var Escaper
20+
*/
21+
private $escaper;
22+
1323
/**
1424
* Retrieve params and put javascript into iframe
1525
*
@@ -19,7 +29,7 @@ public function execute()
1929
{
2030
$helper = $this->dataFactory->create('frontend');
2131

22-
$redirectParams = $this->getRequest()->getParams();
32+
$redirectParams = $this->filterData($this->getRequest()->getParams());
2333
$params = [];
2434
if (!empty($redirectParams['success'])
2535
&& isset($redirectParams['x_invoice_num'])
@@ -44,4 +54,30 @@ public function execute()
4454
$this->_view->addPageLayoutHandles();
4555
$this->_view->loadLayout(false)->renderLayout();
4656
}
57+
58+
/**
59+
* Escape xss in request data
60+
* @param array $data
61+
* @return array
62+
*/
63+
private function filterData(array $data)
64+
{
65+
$self = $this;
66+
array_walk($data, function (&$item) use ($self) {
67+
$item = $self->getEscaper()->escapeXssInUrl($item);
68+
});
69+
return $data;
70+
}
71+
72+
/**
73+
* Get Escaper instance
74+
* @return Escaper
75+
*/
76+
private function getEscaper()
77+
{
78+
if (!$this->escaper) {
79+
$this->escaper = ObjectManager::getInstance()->get(Escaper::class);
80+
}
81+
return $this->escaper;
82+
}
4783
}

app/code/Magento/Authorizenet/Test/Unit/Controller/Directpost/Payment/PlaceTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public function textExecuteFailedPlaceOrderDataProvider()
280280
{
281281
$objectFailed = new \Magento\Framework\DataObject();
282282
$objectFailed->setData('error', true);
283-
$objectFailed->setData('error_messages', __('Cannot place order.'));
283+
$objectFailed->setData('error_messages', __('Unable to place order. Please try again later.'));
284284

285285
return [
286286
[
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Authorizenet\Test\Unit\Controller\Directpost\Payment;
7+
8+
use Magento\Authorizenet\Controller\Directpost\Payment\Redirect;
9+
use Magento\Framework\App\RequestInterface;
10+
use Magento\Framework\App\ViewInterface;
11+
use Magento\Framework\Escaper;
12+
use Magento\Framework\Registry;
13+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
14+
use Magento\Payment\Block\Transparent\Iframe;
15+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
16+
17+
/**
18+
* Class RedirectTest
19+
*/
20+
class RedirectTest extends \PHPUnit_Framework_TestCase
21+
{
22+
/**
23+
* @var RequestInterface|MockObject
24+
*/
25+
private $request;
26+
27+
/**
28+
* @var ViewInterface|MockObject
29+
*/
30+
private $view;
31+
32+
/**
33+
* @var Registry|MockObject
34+
*/
35+
private $coreRegistry;
36+
37+
/**
38+
* @var Escaper|MockObject
39+
*/
40+
private $escaper;
41+
42+
/**
43+
* @var Redirect
44+
*/
45+
private $controller;
46+
47+
protected function setUp()
48+
{
49+
$objectManager = new ObjectManager($this);
50+
51+
$this->request = static::getMockForAbstractClass(RequestInterface::class);
52+
53+
$this->view = static::getMockForAbstractClass(ViewInterface::class);
54+
55+
$this->coreRegistry = static::getMockBuilder(Registry::class)
56+
->disableOriginalConstructor()
57+
->setMethods(['register'])
58+
->getMock();
59+
60+
$this->escaper = static::getMockBuilder(Escaper::class)
61+
->disableOriginalConstructor()
62+
->setMethods(['escapeXssInUrl'])
63+
->getMock();
64+
65+
$this->controller = $objectManager->getObject(Redirect::class, [
66+
'request' => $this->request,
67+
'view' => $this->view,
68+
'coreRegistry' => $this->coreRegistry
69+
]);
70+
71+
$refClass = new \ReflectionClass(Redirect::class);
72+
$refProperty = $refClass->getProperty('escaper');
73+
$refProperty->setAccessible(true);
74+
$refProperty->setValue($this->controller, $this->escaper);
75+
}
76+
77+
/**
78+
* @covers \Magento\Authorizenet\Controller\Directpost\Payment\Redirect::execute
79+
*/
80+
public function testExecute()
81+
{
82+
$url = 'http://test.com/redirect?=test';
83+
$params = [
84+
'order_success' => $url
85+
];
86+
$this->request->expects(static::once())
87+
->method('getParams')
88+
->willReturn($params);
89+
90+
$this->escaper->expects(static::once())
91+
->method('escapeXssInUrl')
92+
->with($url)
93+
->willReturn($url);
94+
95+
$this->coreRegistry->expects(static::once())
96+
->method('register')
97+
->with(Iframe::REGISTRY_KEY, $params);
98+
99+
$this->view->expects(static::once())
100+
->method('addPageLayoutHandles');
101+
$this->view->expects(static::once())
102+
->method('loadLayout')
103+
->with(false)
104+
->willReturnSelf();
105+
$this->view->expects(static::once())
106+
->method('renderLayout');
107+
108+
$this->controller->execute();
109+
}
110+
}

app/code/Magento/Authorizenet/i18n/en_US.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"Order saving error: %1","Order saving error: %1"
33
"Please choose a payment method.","Please choose a payment method."
44
"We can\'t process your order right now. Please try again later.","We can\'t process your order right now. Please try again later."
5-
"Cannot place order.","Cannot place order."
5+
"Unable to place order. Please try again later.","Unable to place order. Please try again later."
66
"Credit Card: xxxx-%1","Credit Card: xxxx-%1"
77
"amount %1","amount %1"
88
failed.,failed.

app/code/Magento/Braintree/view/adminhtml/web/js/vault.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
define([
88
'jquery',
99
'uiComponent',
10-
'Magento_Ui/js/modal/alert'
11-
], function ($, Class, alert) {
10+
'Magento_Ui/js/modal/alert',
11+
'Magento_Checkout/js/model/full-screen-loader'
12+
], function ($, Class, alert, fullScreenLoader) {
1213
'use strict';
1314

1415
return Class.extend({
@@ -83,7 +84,7 @@ define([
8384
submitOrder: function () {
8485
this.$selector.validate().form();
8586
this.$selector.trigger('afterValidate.beforeSubmit');
86-
$('body').trigger('processStop');
87+
fullScreenLoader.stopLoader();
8788

8889
// validate parent form
8990
if (this.$selector.validate().errorList.length) {
@@ -105,21 +106,20 @@ define([
105106
getPaymentMethodNonce: function () {
106107
var self = this;
107108

108-
$('body').trigger('processStart');
109+
fullScreenLoader.startLoader();
110+
109111
$.get(self.nonceUrl, {
110112
'public_hash': self.publicHash
111-
})
112-
.done(function (response) {
113-
$('body').trigger('processStop');
114-
self.setPaymentDetails(response.paymentMethodNonce);
115-
self.placeOrder();
116-
})
117-
.fail(function (response) {
118-
var failed = JSON.parse(response.responseText);
119-
120-
$('body').trigger('processStop');
121-
self.error(failed.message);
122-
});
113+
}).done(function (response) {
114+
self.setPaymentDetails(response.paymentMethodNonce);
115+
self.placeOrder();
116+
}).fail(function (response) {
117+
var failed = JSON.parse(response.responseText);
118+
119+
self.error(failed.message);
120+
}).always(function () {
121+
fullScreenLoader.stopLoader();
122+
});
123123
},
124124

125125
/**

app/code/Magento/Bundle/Model/LinkManagement.php

+18-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Magento\Catalog\Api\Data\ProductInterface;
1010
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Framework\App\ObjectManager;
1112
use Magento\Framework\Exception\CouldNotSaveException;
1213
use Magento\Framework\Exception\InputException;
1314
use Magento\Framework\Model\Entity\MetadataPool;
@@ -50,7 +51,7 @@ class LinkManagement implements \Magento\Bundle\Api\ProductLinkManagementInterfa
5051
/**
5152
* @var MetadataPool
5253
*/
53-
protected $metadataPool;
54+
private $metadataPool;
5455

5556
/**
5657
* @param ProductRepositoryInterface $productRepository
@@ -60,7 +61,6 @@ class LinkManagement implements \Magento\Bundle\Api\ProductLinkManagementInterfa
6061
* @param \Magento\Bundle\Model\ResourceModel\Option\CollectionFactory $optionCollection
6162
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
6263
* @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
63-
* @param MetadataPool $metadataPool
6464
*/
6565
public function __construct(
6666
ProductRepositoryInterface $productRepository,
@@ -69,8 +69,7 @@ public function __construct(
6969
\Magento\Bundle\Model\ResourceModel\BundleFactory $bundleFactory,
7070
\Magento\Bundle\Model\ResourceModel\Option\CollectionFactory $optionCollection,
7171
\Magento\Store\Model\StoreManagerInterface $storeManager,
72-
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
73-
MetadataPool $metadataPool
72+
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper
7473
) {
7574
$this->productRepository = $productRepository;
7675
$this->linkFactory = $linkFactory;
@@ -79,7 +78,6 @@ public function __construct(
7978
$this->optionCollection = $optionCollection;
8079
$this->storeManager = $storeManager;
8180
$this->dataObjectHelper = $dataObjectHelper;
82-
$this->metadataPool = $metadataPool;
8381
}
8482

8583
/**
@@ -147,7 +145,7 @@ public function saveChild(
147145
if (!$selectionModel->getId()) {
148146
throw new InputException(__('Can not find product link with id "%1"', [$linkedProduct->getId()]));
149147
}
150-
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
148+
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
151149
$selectionModel = $this->mapProductLinkToSelectionModel(
152150
$selectionModel,
153151
$linkedProduct,
@@ -231,7 +229,7 @@ public function addChild(
231229
);
232230
}
233231

234-
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
232+
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
235233
/* @var $resource \Magento\Bundle\Model\ResourceModel\Bundle */
236234
$resource = $this->bundleFactory->create();
237235
$selections = $resource->getSelectionsData($product->getData($linkField));
@@ -303,7 +301,7 @@ public function removeChild($sku, $optionId, $childSku)
303301
__('Requested bundle option product doesn\'t exist')
304302
);
305303
}
306-
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
304+
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
307305
/* @var $resource \Magento\Bundle\Model\ResourceModel\Bundle */
308306
$resource = $this->bundleFactory->create();
309307
$resource->dropAllUnneededSelections($product->getData($linkField), $excludeSelectionIds);
@@ -366,4 +364,16 @@ private function getOptions(\Magento\Catalog\Api\Data\ProductInterface $product)
366364
$options = $optionCollection->appendSelections($selectionCollection);
367365
return $options;
368366
}
367+
368+
/**
369+
* Get MetadataPool instance
370+
* @return MetadataPool
371+
*/
372+
private function getMetadataPool()
373+
{
374+
if (!$this->metadataPool) {
375+
$this->metadataPool = ObjectManager::getInstance()->get(MetadataPool::class);
376+
}
377+
return $this->metadataPool;
378+
}
369379
}

0 commit comments

Comments
 (0)