Skip to content

Commit 684e8fb

Browse files
committed
Magento_CurrencySymbol module. Replace replace deprecated message functions
1 parent ea71192 commit 684e8fb

File tree

5 files changed

+91
-17
lines changed

5 files changed

+91
-17
lines changed

app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/FetchRates.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
@@ -13,6 +12,9 @@
1312
use Magento\Framework\Controller\ResultFactory;
1413
use Magento\CurrencySymbol\Controller\Adminhtml\System\Currency as CurrencyAction;
1514

15+
/**
16+
* Class FetchRates
17+
*/
1618
class FetchRates extends CurrencyAction implements HttpGetActionInterface, HttpPostActionInterface
1719
{
1820
/**
@@ -41,20 +43,20 @@ public function execute()
4143
}
4244
$rates = $importModel->fetchRates();
4345
$errors = $importModel->getMessages();
44-
if (sizeof($errors) > 0) {
46+
if (count($errors) > 0) {
4547
foreach ($errors as $error) {
46-
$this->messageManager->addWarning($error);
48+
$this->messageManager->addWarningMessage($error);
4749
}
48-
$this->messageManager->addWarning(
50+
$this->messageManager->addWarningMessage(
4951
__('Click "Save" to apply the rates we found.')
5052
);
5153
} else {
52-
$this->messageManager->addSuccess(__('Click "Save" to apply the rates we found.'));
54+
$this->messageManager->addSuccessMessage(__('Click "Save" to apply the rates we found.'));
5355
}
5456

5557
$backendSession->setRates($rates);
5658
} catch (\Exception $e) {
57-
$this->messageManager->addError($e->getMessage());
59+
$this->messageManager->addErrorMessage($e->getMessage());
5860
}
5961

6062
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */

app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/SaveRates.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
@@ -9,6 +8,9 @@
98

109
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
1110

11+
/**
12+
* Class SaveRates
13+
*/
1214
class SaveRates extends \Magento\CurrencySymbol\Controller\Adminhtml\System\Currency implements HttpPostActionInterface
1315
{
1416
/**
@@ -23,22 +25,23 @@ public function execute()
2325
try {
2426
foreach ($data as $currencyCode => $rate) {
2527
foreach ($rate as $currencyTo => $value) {
26-
$value = abs($this->_objectManager->get(
27-
\Magento\Framework\Locale\FormatInterface::class
28-
)->getNumber($value));
28+
$value = abs(
29+
$this->_objectManager->get(\Magento\Framework\Locale\FormatInterface::class)
30+
->getNumber($value)
31+
);
2932
$data[$currencyCode][$currencyTo] = $value;
3033
if ($value == 0) {
31-
$this->messageManager->addWarning(
34+
$this->messageManager->addWarningMessage(
3235
__('Please correct the input data for "%1 => %2" rate.', $currencyCode, $currencyTo)
3336
);
3437
}
3538
}
3639
}
3740

3841
$this->_objectManager->create(\Magento\Directory\Model\Currency::class)->saveRates($data);
39-
$this->messageManager->addSuccess(__('All valid rates have been saved.'));
42+
$this->messageManager->addSuccessMessage(__('All valid rates have been saved.'));
4043
} catch (\Exception $e) {
41-
$this->messageManager->addError($e->getMessage());
44+
$this->messageManager->addErrorMessage($e->getMessage());
4245
}
4346
}
4447

app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currencysymbol/Save.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
76
namespace Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol;
87

98
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
109

10+
/**
11+
* Class Save
12+
*/
1113
class Save extends \Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol implements HttpPostActionInterface
1214
{
1315
/**
@@ -29,9 +31,9 @@ public function execute()
2931
try {
3032
$this->_objectManager->create(\Magento\CurrencySymbol\Model\System\Currencysymbol::class)
3133
->setCurrencySymbolsData($symbolsDataArray);
32-
$this->messageManager->addSuccess(__('You applied the custom currency symbols.'));
34+
$this->messageManager->addSuccessMessage(__('You applied the custom currency symbols.'));
3335
} catch (\Exception $e) {
34-
$this->messageManager->addError($e->getMessage());
36+
$this->messageManager->addErrorMessage($e->getMessage());
3537
}
3638

3739
$this->getResponse()->setRedirect($this->_redirect->getRedirectUrl($this->getUrl('*')));
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CurrencySymbol\Test\Unit\Controller\Adminhtml\System\Currency;
7+
8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
9+
10+
/**
11+
* Class SaveRatesTest
12+
*/
13+
class SaveRatesTest extends \PHPUnit\Framework\TestCase
14+
{
15+
/**
16+
* @var \Magento\CurrencySymbol\Controller\Adminhtml\System\Currency\SaveRates
17+
*/
18+
protected $action;
19+
20+
/**
21+
* @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
protected $requestMock;
24+
25+
/**
26+
* @var \Magento\Framework\App\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
protected $responseMock;
29+
30+
/**
31+
*
32+
*/
33+
protected function setUp()
34+
{
35+
$objectManager = new ObjectManager($this);
36+
37+
$this->requestMock = $this->createMock(\Magento\Framework\App\RequestInterface::class);
38+
39+
$this->responseMock = $this->createPartialMock(
40+
\Magento\Framework\App\ResponseInterface::class,
41+
['setRedirect', 'sendResponse']
42+
);
43+
44+
$this->action = $objectManager->getObject(
45+
\Magento\CurrencySymbol\Controller\Adminhtml\System\Currency\SaveRates::class,
46+
[
47+
'request' => $this->requestMock,
48+
'response' => $this->responseMock,
49+
]
50+
);
51+
}
52+
53+
/**
54+
*
55+
*/
56+
public function testWithNullRateExecute()
57+
{
58+
$this->requestMock->expects($this->once())
59+
->method('getParam')
60+
->with('rate')
61+
->willReturn(null);
62+
63+
$this->responseMock->expects($this->once())->method('setRedirect');
64+
65+
$this->action->execute();
66+
}
67+
}

app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/Currencysymbol/SaveTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function testExecute()
128128
->willReturn($this->filterManagerMock);
129129

130130
$this->messageManagerMock->expects($this->once())
131-
->method('addSuccess')
131+
->method('addSuccessMessage')
132132
->with(__('You applied the custom currency symbols.'));
133133

134134
$this->action->execute();

0 commit comments

Comments
 (0)