Skip to content

Commit 2de860c

Browse files
ENGCOM-5967: Magento_CurrencySymbol module. Replace replace deprecated message functions #24754
- Merge Pull Request #24754 from atwixfirster/magento2:module-currency-symbol-replace-deprecated-message-func - Merged commits: 1. 684e8fb 2. f05dd7f
2 parents 6f1a6f7 + f05dd7f commit 2de860c

File tree

7 files changed

+129
-19
lines changed

7 files changed

+129
-19
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();

dev/tests/integration/testsuite/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/FetchRatesTest.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,30 @@
66

77
namespace Magento\CurrencySymbol\Controller\Adminhtml\System\Currency;
88

9+
use Magento\Framework\Escaper;
10+
911
/**
1012
* Fetch Rates Test
1113
*/
1214
class FetchRatesTest extends \Magento\TestFramework\TestCase\AbstractBackendController
1315
{
16+
/**
17+
* @var Escaper
18+
*/
19+
private $escaper;
20+
21+
/**
22+
* Initial setup
23+
*/
24+
protected function setUp()
25+
{
26+
$this->escaper = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
27+
Escaper::class
28+
);
29+
30+
parent::setUp();
31+
}
32+
1433
/**
1534
* Test fetch action without service
1635
*
@@ -46,7 +65,11 @@ public function testFetchRatesActionWithNonexistentService(): void
4665
$this->dispatch('backend/admin/system_currency/fetchRates');
4766

4867
$this->assertSessionMessages(
49-
$this->contains("The import model can't be initialized. Verify the model and try again."),
68+
$this->contains(
69+
$this->escaper->escapeHtml(
70+
"The import model can't be initialized. Verify the model and try again."
71+
)
72+
),
5073
\Magento\Framework\Message\MessageInterface::TYPE_ERROR
5174
);
5275
}

dev/tests/integration/testsuite/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/SaveRatesTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,23 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\CurrencySymbol\Controller\Adminhtml\System\Currency;
78

89
use Magento\Framework\App\Request\Http as HttpRequest;
10+
use Magento\Framework\Escaper;
911

1012
class SaveRatesTest extends \Magento\TestFramework\TestCase\AbstractBackendController
1113
{
1214

1315
/** @var \Magento\Directory\Model\Currency $currencyRate */
1416
protected $currencyRate;
1517

18+
/**
19+
* @var Escaper
20+
*/
21+
private $escaper;
22+
1623
/**
1724
* Initial setup
1825
*/
@@ -21,6 +28,10 @@ protected function setUp()
2128
$this->currencyRate = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
2229
\Magento\Directory\Model\Currency::class
2330
);
31+
$this->escaper = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
32+
Escaper::class
33+
);
34+
2435
parent::setUp();
2536
}
2637

@@ -89,7 +100,9 @@ public function testSaveWithWarningAction()
89100

90101
$this->assertSessionMessages(
91102
$this->contains(
92-
(string)__('Please correct the input data for "%1 => %2" rate.', $currencyCode, $currencyTo)
103+
$this->escaper->escapeHtml(
104+
(string)__('Please correct the input data for "%1 => %2" rate.', $currencyCode, $currencyTo)
105+
)
93106
),
94107
\Magento\Framework\Message\MessageInterface::TYPE_WARNING
95108
);

0 commit comments

Comments
 (0)