Skip to content

Commit ffc1580

Browse files
author
mduuude
committed
MAGETWO-83340: [2.3] Provide possibility to customize error messages from payment methods
- refactored integration test, added case for default message
1 parent 35a4752 commit ffc1580

File tree

1 file changed

+40
-26
lines changed

1 file changed

+40
-26
lines changed

dev/tests/integration/testsuite/Magento/Checkout/Api/PaymentInformationManagementTest.php

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Braintree\Model\Ui\ConfigProvider;
1313
use Magento\Framework\Api\SearchCriteriaBuilder;
1414
use Magento\Framework\App\State;
15+
use Magento\Framework\App\Area;
1516
use Magento\Quote\Api\CartRepositoryInterface;
1617
use Magento\Quote\Api\Data\CartInterface;
1718
use Magento\Quote\Api\Data\PaymentInterface;
@@ -20,6 +21,11 @@
2021
use PHPUnit\Framework\TestCase;
2122
use PHPUnit_Framework_MockObject_MockObject as MockObject;
2223

24+
/**
25+
* Class PaymentInformationManagementTest
26+
*
27+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
28+
*/
2329
class PaymentInformationManagementTest extends TestCase
2430
{
2531
/**
@@ -64,9 +70,16 @@ protected function tearDown()
6470
* @magentoConfigFixture current_store payment/braintree/active 1
6571
* @dataProvider getErrorPerAreaDataProvider
6672
* @expectedException \Magento\Framework\Exception\CouldNotSaveException
73+
* @param string $area
74+
* @param array $testErrorCodes
75+
* @param string $expectedOutput
76+
* @throws \Magento\Framework\Exception\LocalizedException
6777
*/
68-
public function testSavePaymentInformationAndPlaceOrderWithErrors(string $area, string $errorMessage)
69-
{
78+
public function testSavePaymentInformationAndPlaceOrderWithErrors(
79+
string $area,
80+
array $testErrorCodes,
81+
string $expectedOutput
82+
) {
7083
/** @var State $state */
7184
$state = $this->objectManager->get(State::class);
7285
$state->setAreaCode($area);
@@ -77,31 +90,18 @@ public function testSavePaymentInformationAndPlaceOrderWithErrors(string $area,
7790
$payment = $this->objectManager->create(PaymentInterface::class);
7891
$payment->setMethod(ConfigProvider::CODE);
7992

80-
$errors = [
81-
'errors' => [
82-
[
83-
'code' => 'fake_code',
84-
'attribute' => 'base',
85-
'message' => 'Error message should not be mapped.'
86-
],
87-
[
88-
'code' => 81802,
89-
'attribute' => 'base',
90-
'message' => 'Company is too long.'
91-
],
92-
[
93-
'code' => 91511,
94-
'attribute' => 'base',
95-
'message' => 'Customer does not have any credit cards.'
96-
]
97-
]
98-
];
93+
$errors = ['errors' => []];
94+
95+
foreach ($testErrorCodes as $testErrorCode) {
96+
array_push($errors['errors'], ['code' => $testErrorCode]);
97+
}
98+
9999
$response = new Error(['errors' => $errors]);
100100

101101
$this->client->method('placeRequest')
102102
->willReturn(['object' => $response]);
103103

104-
$this->expectExceptionMessage($errorMessage);
104+
$this->expectExceptionMessage($expectedOutput);
105105

106106
/** @var PaymentInformationManagementInterface $paymentInformationManagement */
107107
$paymentInformationManagement = $this->objectManager->get(PaymentInformationManagementInterface::class);
@@ -118,10 +118,24 @@ public function testSavePaymentInformationAndPlaceOrderWithErrors(string $area,
118118
*/
119119
public function getErrorPerAreaDataProvider()
120120
{
121-
$globalAreaError = 'Company is too long.';
121+
$testErrorGlobal = ['code' => 81802, 'message' => 'Company is too long.'];
122+
$testErrorAdmin = ['code' => 91511, 'message' => 'Customer does not have any credit cards.'];
123+
$testErrorFake = ['code' => 'fake_code', 'message' => 'Error message should not be mapped.'];
124+
122125
return [
123-
['area' => 'frontend', 'error' => $globalAreaError],
124-
['area' => 'adminhtml', 'error' => $globalAreaError . PHP_EOL . 'Customer does not have any credit cards.'],
126+
[
127+
Area::AREA_FRONTEND,
128+
[$testErrorAdmin['code'], $testErrorFake['code']],
129+
'Transaction has been declined. Please try again later.'
130+
], [
131+
Area::AREA_FRONTEND,
132+
[$testErrorGlobal['code'], $testErrorAdmin['code'], $testErrorFake['code']],
133+
$testErrorGlobal['message']
134+
], [
135+
Area::AREA_ADMINHTML,
136+
[$testErrorGlobal['code'], $testErrorAdmin['code'], $testErrorFake['code']],
137+
$testErrorGlobal['message'] . PHP_EOL . $testErrorAdmin['message']
138+
],
125139
];
126140
}
127141

@@ -131,7 +145,7 @@ public function getErrorPerAreaDataProvider()
131145
* @param string $reservedOrderId
132146
* @return CartInterface
133147
*/
134-
private function getQuote(string $reservedOrderId) : CartInterface
148+
private function getQuote(string $reservedOrderId): CartInterface
135149
{
136150
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
137151
$searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class);

0 commit comments

Comments
 (0)