Skip to content

Commit 310532c

Browse files
committed
#9347: Merge branch '2.3-develop' of github.com:magento/magento2ce into MAGETWO-70886-magento-magento2-9347
2 parents 7ea0611 + 07c2590 commit 310532c

File tree

178 files changed

+6273
-1651
lines changed

Some content is hidden

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

178 files changed

+6273
-1651
lines changed

app/code/Magento/Backend/view/adminhtml/web/js/media-uploader.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,19 @@ define([
1313
'jquery',
1414
'mage/template',
1515
'Magento_Ui/js/modal/alert',
16+
'Magento_Ui/js/form/element/file-uploader',
1617
'mage/translate',
1718
'jquery/file-uploader'
18-
], function ($, mageTemplate, alert) {
19+
], function ($, mageTemplate, alert, FileUploader) {
1920
'use strict';
2021

22+
var fileUploader = new FileUploader({
23+
dataScope: '',
24+
isMultipleFiles: true
25+
});
26+
27+
fileUploader.initUploader();
28+
2129
$.widget('mage.mediaUploader', {
2230

2331
/**
@@ -79,10 +87,9 @@ define([
7987
if (data.result && !data.result.error) {
8088
self.element.trigger('addItem', data.result);
8189
} else {
82-
alert({
83-
content: $.mage.__('We don\'t recognize or support this file extension type.')
84-
});
90+
fileUploader.aggregateError(data.files[0].name, data.result.error);
8591
}
92+
8693
self.element.find('#' + data.fileId).remove();
8794
},
8895

@@ -108,7 +115,9 @@ define([
108115
.delay(2000)
109116
.hide('highlight')
110117
.remove();
111-
}
118+
},
119+
120+
stop: fileUploader.uploaderConfig.stop
112121
});
113122

114123
this.element.find('input[type=file]').fileupload('option', {
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\Braintree\Gateway\Validator;
9+
10+
use Braintree\Error\ErrorCollection;
11+
use Braintree\Error\Validation;
12+
use Braintree\Result\Error;
13+
use Braintree\Result\Successful;
14+
15+
/**
16+
* Processes errors codes from Braintree response.
17+
*/
18+
class ErrorCodeProvider
19+
{
20+
/**
21+
* Retrieves list of error codes from Braintree response.
22+
*
23+
* @param Successful|Error $response
24+
* @return array
25+
*/
26+
public function getErrorCodes($response): array
27+
{
28+
$result = [];
29+
if (!$response instanceof Error) {
30+
return $result;
31+
}
32+
33+
/** @var ErrorCollection $collection */
34+
$collection = $response->errors;
35+
36+
/** @var Validation $error */
37+
foreach ($collection->deepAll() as $error) {
38+
$result[] = $error->code;
39+
}
40+
41+
return $result;
42+
}
43+
}

app/code/Magento/Braintree/Gateway/Validator/GeneralResponseValidator.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,26 @@ class GeneralResponseValidator extends AbstractValidator
1818
*/
1919
protected $subjectReader;
2020

21+
/**
22+
* @var ErrorCodeProvider
23+
*/
24+
private $errorCodeProvider;
25+
2126
/**
2227
* Constructor
2328
*
2429
* @param ResultInterfaceFactory $resultFactory
2530
* @param SubjectReader $subjectReader
31+
* @param ErrorCodeProvider $errorCodeProvider
2632
*/
27-
public function __construct(ResultInterfaceFactory $resultFactory, SubjectReader $subjectReader)
28-
{
33+
public function __construct(
34+
ResultInterfaceFactory $resultFactory,
35+
SubjectReader $subjectReader,
36+
ErrorCodeProvider $errorCodeProvider
37+
) {
2938
parent::__construct($resultFactory);
3039
$this->subjectReader = $subjectReader;
40+
$this->errorCodeProvider = $errorCodeProvider;
3141
}
3242

3343
/**
@@ -49,8 +59,9 @@ public function validate(array $validationSubject)
4959
$errorMessages = array_merge($errorMessages, $validationResult[1]);
5060
}
5161
}
62+
$errorCodes = $this->errorCodeProvider->getErrorCodes($response);
5263

53-
return $this->createResult($isValid, $errorMessages);
64+
return $this->createResult($isValid, $errorMessages, $errorCodes);
5465
}
5566

5667
/**
@@ -62,7 +73,7 @@ protected function getResponseValidators()
6273
function ($response) {
6374
return [
6475
property_exists($response, 'success') && $response->success === true,
65-
[__('Braintree error response.')]
76+
[$response->message ?? __('Braintree error response.')]
6677
];
6778
}
6879
];

app/code/Magento/Braintree/Test/Unit/Gateway/Command/GetPaymentNonceCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ protected function setUp()
9999
->getMock();
100100

101101
$this->validationResultMock = $this->getMockBuilder(ResultInterface::class)
102-
->setMethods(['isValid', 'getFailsDescription'])
102+
->setMethods(['isValid', 'getFailsDescription', 'getErrorCodes'])
103103
->getMock();
104104

105105
$this->responseValidatorMock = $this->getMockBuilder(PaymentNonceResponseValidator::class)

app/code/Magento/Braintree/Test/Unit/Gateway/Validator/GeneralResponseValidatorTest.php

Lines changed: 59 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
*/
66
namespace Magento\Braintree\Test\Unit\Gateway\Validator;
77

8-
use Braintree\Transaction;
8+
use Braintree\Result\Error;
9+
use Magento\Braintree\Gateway\SubjectReader;
10+
use Magento\Braintree\Gateway\Validator\ErrorCodeProvider;
11+
use Magento\Braintree\Gateway\Validator\GeneralResponseValidator;
912
use Magento\Framework\Phrase;
10-
use Magento\Payment\Gateway\Validator\ResultInterface;
13+
use Magento\Payment\Gateway\Validator\Result;
1114
use Magento\Payment\Gateway\Validator\ResultInterfaceFactory;
12-
use Magento\Braintree\Gateway\Validator\GeneralResponseValidator;
13-
use Magento\Braintree\Gateway\SubjectReader;
15+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1416

1517
class GeneralResponseValidatorTest extends \PHPUnit\Framework\TestCase
1618
{
@@ -20,14 +22,9 @@ class GeneralResponseValidatorTest extends \PHPUnit\Framework\TestCase
2022
private $responseValidator;
2123

2224
/**
23-
* @var ResultInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject
24-
*/
25-
private $resultInterfaceFactoryMock;
26-
27-
/**
28-
* @var SubjectReader|\PHPUnit_Framework_MockObject_MockObject
25+
* @var ResultInterfaceFactory|MockObject
2926
*/
30-
private $subjectReaderMock;
27+
private $resultInterfaceFactory;
3128

3229
/**
3330
* Set up
@@ -36,85 +33,105 @@ class GeneralResponseValidatorTest extends \PHPUnit\Framework\TestCase
3633
*/
3734
protected function setUp()
3835
{
39-
$this->resultInterfaceFactoryMock = $this->getMockBuilder(
40-
\Magento\Payment\Gateway\Validator\ResultInterfaceFactory::class
41-
)->disableOriginalConstructor()
42-
->setMethods(['create'])
43-
->getMock();
44-
$this->subjectReaderMock = $this->getMockBuilder(SubjectReader::class)
36+
$this->resultInterfaceFactory = $this->getMockBuilder(ResultInterfaceFactory::class)
4537
->disableOriginalConstructor()
38+
->setMethods(['create'])
4639
->getMock();
4740

4841
$this->responseValidator = new GeneralResponseValidator(
49-
$this->resultInterfaceFactoryMock,
50-
$this->subjectReaderMock
42+
$this->resultInterfaceFactory,
43+
new SubjectReader(),
44+
new ErrorCodeProvider()
5145
);
5246
}
5347

5448
/**
55-
* Run test for validate method
49+
* Checks a case when the validator processes successful and failed transactions.
5650
*
5751
* @param array $validationSubject
5852
* @param bool $isValid
5953
* @param Phrase[] $messages
54+
* @param array $errorCodes
6055
* @return void
6156
*
6257
* @dataProvider dataProviderTestValidate
6358
*/
64-
public function testValidate(array $validationSubject, $isValid, $messages)
59+
public function testValidate(array $validationSubject, bool $isValid, $messages, array $errorCodes)
6560
{
66-
/** @var ResultInterface|\PHPUnit_Framework_MockObject_MockObject $resultMock */
67-
$resultMock = $this->createMock(ResultInterface::class);
68-
69-
$this->subjectReaderMock->expects(self::once())
70-
->method('readResponseObject')
71-
->with($validationSubject)
72-
->willReturn($validationSubject['response']['object']);
61+
$result = new Result($isValid, $messages);
7362

74-
$this->resultInterfaceFactoryMock->expects(self::once())
75-
->method('create')
63+
$this->resultInterfaceFactory->method('create')
7664
->with([
7765
'isValid' => $isValid,
78-
'failsDescription' => $messages
66+
'failsDescription' => $messages,
67+
'errorCodes' => $errorCodes
7968
])
80-
->willReturn($resultMock);
69+
->willReturn($result);
8170

82-
$actualMock = $this->responseValidator->validate($validationSubject);
71+
$actual = $this->responseValidator->validate($validationSubject);
8372

84-
self::assertEquals($resultMock, $actualMock);
73+
self::assertEquals($result, $actual);
8574
}
8675

8776
/**
77+
* Gets variations for different type of response.
78+
*
8879
* @return array
8980
*/
9081
public function dataProviderTestValidate()
9182
{
92-
$successTrue = new \stdClass();
93-
$successTrue->success = true;
83+
$successTransaction = new \stdClass();
84+
$successTransaction->success = true;
85+
86+
$failureTransaction = new \stdClass();
87+
$failureTransaction->success = false;
88+
$failureTransaction->message = 'Transaction was failed.';
9489

95-
$successFalse = new \stdClass();
96-
$successFalse->success = false;
90+
$errors = [
91+
'errors' => [
92+
[
93+
'code' => 81804,
94+
'attribute' => 'base',
95+
'message' => 'Cannot process transaction.'
96+
]
97+
]
98+
];
99+
$errorTransaction = new Error(['errors' => $errors]);
97100

98101
return [
99102
[
100103
'validationSubject' => [
101104
'response' => [
102-
'object' => $successTrue
105+
'object' => $successTransaction
103106
],
104107
],
105108
'isValid' => true,
106-
[]
109+
[],
110+
'errorCodes' => []
111+
],
112+
[
113+
'validationSubject' => [
114+
'response' => [
115+
'object' => $failureTransaction
116+
]
117+
],
118+
'isValid' => false,
119+
[
120+
__('Transaction was failed.')
121+
],
122+
'errorCodes' => []
107123
],
108124
[
109125
'validationSubject' => [
110126
'response' => [
111-
'object' => $successFalse
127+
'object' => $errorTransaction
112128
]
113129
],
114130
'isValid' => false,
115131
[
116132
__('Braintree error response.')
117-
]
133+
],
134+
'errorCodes' => ['81804']
118135
]
119136
];
120137
}

0 commit comments

Comments
 (0)