Skip to content

Commit 5aeb008

Browse files
committed
MC-29261: [Magento Cloud] - When admin URL is different to front-base URL admin redirects to storefront
1 parent 61508b3 commit 5aeb008

File tree

2 files changed

+47
-37
lines changed
  • app/code/Magento/CurrencySymbol
    • Controller/Adminhtml/System/Currencysymbol
    • Test/Unit/Controller/Adminhtml/System/Currencysymbol

2 files changed

+47
-37
lines changed

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

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
*/
66
namespace Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol;
77

8+
use Magento\Backend\App\Action;
89
use Magento\Backend\Model\View\Result\Redirect;
910
use Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol as CurrencysymbolController;
10-
use Magento\CurrencySymbol\Model\System\Currencysymbol;
11+
use Magento\CurrencySymbol\Model\System\CurrencysymbolFactory;
1112
use Magento\Framework\App\Action\HttpPostActionInterface;
1213
use Magento\Framework\Controller\ResultInterface;
1314
use Magento\Framework\Filter\FilterManager;
@@ -17,6 +18,31 @@
1718
*/
1819
class Save extends CurrencysymbolController implements HttpPostActionInterface
1920
{
21+
/**
22+
* @var FilterManager
23+
*/
24+
private $filterManager;
25+
26+
/**
27+
* @var CurrencysymbolFactory
28+
*/
29+
private $currencySymbolFactory;
30+
31+
/**
32+
* @param Action\Context $context
33+
* @param FilterManager $filterManager
34+
* @param CurrencysymbolFactory $currencySymbolFactory
35+
*/
36+
public function __construct(
37+
Action\Context $context,
38+
FilterManager $filterManager,
39+
CurrencysymbolFactory $currencySymbolFactory
40+
) {
41+
parent::__construct($context);
42+
$this->filterManager = $filterManager;
43+
$this->currencySymbolFactory = $currencySymbolFactory;
44+
}
45+
2046
/**
2147
* Save custom Currency symbol
2248
*
@@ -29,15 +55,13 @@ public function execute()
2955
$symbolsDataArray = $this->getRequest()->getParam('custom_currency_symbol', null);
3056
if (is_array($symbolsDataArray)) {
3157
foreach ($symbolsDataArray as &$symbolsData) {
32-
/** @var $filterManager FilterManager */
33-
$filterManager = $this->_objectManager->get(FilterManager::class);
34-
$symbolsData = $filterManager->stripTags($symbolsData);
58+
$symbolsData = $this->filterManager->stripTags($symbolsData);
3559
}
3660
}
3761

3862
try {
39-
$this->_objectManager->create(Currencysymbol::class)
40-
->setCurrencySymbolsData($symbolsDataArray);
63+
$currencySymbol = $this->currencySymbolFactory->create();
64+
$currencySymbol->setCurrencySymbolsData($symbolsDataArray);
4165
$this->messageManager->addSuccessMessage(__('You applied the custom currency symbols.'));
4266
} catch (\Exception $e) {
4367
$this->messageManager->addErrorMessage($e->getMessage());

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

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
use Magento\Backend\Model\View\Result\RedirectFactory;
1111
use Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol\Save;
1212
use Magento\CurrencySymbol\Model\System\Currencysymbol;
13+
use Magento\CurrencySymbol\Model\System\CurrencysymbolFactory;
1314
use Magento\Framework\App\RequestInterface;
1415
use Magento\Framework\App\Response\RedirectInterface;
1516
use Magento\Framework\App\ResponseInterface;
1617
use Magento\Framework\Filter\FilterManager;
1718
use Magento\Framework\Message\ManagerInterface;
18-
use Magento\Framework\ObjectManagerInterface;
1919
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
2020
use PHPUnit\Framework\TestCase;
2121
use PHPUnit\Framework\MockObject\MockObject;
@@ -45,16 +45,6 @@ class SaveTest extends TestCase
4545
*/
4646
protected $responseMock;
4747

48-
/**
49-
* @var ObjectManagerInterface|MockObject
50-
*/
51-
protected $objectManagerMock;
52-
53-
/**
54-
* @var Currencysymbol|MockObject
55-
*/
56-
protected $currencySymbolMock;
57-
5848
/**
5949
* @var ManagerInterface|MockObject
6050
*/
@@ -73,7 +63,12 @@ class SaveTest extends TestCase
7363
/**
7464
* @var FilterManager|MockObject
7565
*/
76-
protected $filterManagerMock;
66+
private $filterManager;
67+
68+
/**
69+
* @var CurrencysymbolFactory|MockObject
70+
*/
71+
private $currencySymbolFactory;
7772

7873
/**
7974
* @inheritdoc
@@ -88,25 +83,25 @@ protected function setUp()
8883
ResponseInterface::class,
8984
['setRedirect', 'sendResponse']
9085
);
91-
$this->currencySymbolMock = $this->createMock(Currencysymbol::class);
92-
$this->filterManagerMock = $this->createPartialMock(
86+
$this->messageManagerMock = $this->createMock(ManagerInterface::class);
87+
$this->resultRedirectFactory = $this->createMock(RedirectFactory::class);
88+
$this->filterManager = $this->createPartialMock(
9389
FilterManager::class,
9490
['stripTags']
9591
);
96-
$this->objectManagerMock = $this->createMock(ObjectManagerInterface::class);
97-
$this->messageManagerMock = $this->createMock(ManagerInterface::class);
98-
$this->resultRedirectFactory = $this->createMock(RedirectFactory::class);
92+
$this->currencySymbolFactory = $this->createMock(CurrencysymbolFactory::class);
9993

10094
$this->action = $objectManager->getObject(
10195
Save::class,
10296
[
10397
'request' => $this->requestMock,
10498
'response' => $this->responseMock,
105-
'objectManager' => $this->objectManagerMock,
10699
'redirect' => $this->redirectMock,
107100
'helper' => $this->helperMock,
108101
'messageManager' => $this->messageManagerMock,
109102
'resultRedirectFactory' => $this->resultRedirectFactory,
103+
'filterManager' => $this->filterManager,
104+
'currencySymbolFactory' => $this->currencySymbolFactory,
110105
]
111106
);
112107
}
@@ -124,23 +119,14 @@ public function testExecute()
124119
->with('custom_currency_symbol')
125120
->willReturn($symbolsDataArray);
126121

127-
$this->currencySymbolMock->expects($this->once())->method('setCurrencySymbolsData')->with($symbolsDataArray);
128-
129-
$this->filterManagerMock->expects($this->once())
122+
$currencySymbol = $this->createMock(Currencysymbol::class);
123+
$currencySymbol->expects($this->once())->method('setCurrencySymbolsData')->with($symbolsDataArray);
124+
$this->currencySymbolFactory->method('create')->willReturn($currencySymbol);
125+
$this->filterManager->expects($this->once())
130126
->method('stripTags')
131127
->with($firstElement)
132128
->willReturn($firstElement);
133129

134-
$this->objectManagerMock->expects($this->once())
135-
->method('create')
136-
->with(Currencysymbol::class)
137-
->willReturn($this->currencySymbolMock);
138-
139-
$this->objectManagerMock->expects($this->once())
140-
->method('get')
141-
->with(FilterManager::class)
142-
->willReturn($this->filterManagerMock);
143-
144130
$this->messageManagerMock->expects($this->once())
145131
->method('addSuccessMessage')
146132
->with(__('You applied the custom currency symbols.'));

0 commit comments

Comments
 (0)