Skip to content

Commit 9e801de

Browse files
author
Dmytro Voskoboinikov
committed
MAGETWO-88600: Error while saving Theme design configuration
1 parent f947cad commit 9e801de

File tree

2 files changed

+20
-15
lines changed
  • app/code/Magento/Theme

2 files changed

+20
-15
lines changed

app/code/Magento/Theme/Controller/Adminhtml/Design/Config/Save.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Backend\App\Action;
99
use Magento\Framework\App\Request\DataPersistorInterface;
10+
use Magento\Framework\Exception\NotFoundException;
1011
use Magento\Theme\Model\DesignConfigRepository;
1112
use Magento\Backend\App\Action\Context;
1213
use Magento\Framework\Exception\LocalizedException;
@@ -62,9 +63,15 @@ protected function _isAllowed()
6263

6364
/**
6465
* @return \Magento\Framework\Controller\Result\Redirect
66+
*
67+
* @throws NotFoundException
6568
*/
6669
public function execute()
6770
{
71+
if (!$this->getRequest()->isPost()) {
72+
throw new NotFoundException(__('Page not found.'));
73+
}
74+
6875
$resultRedirect = $this->resultRedirectFactory->create();
6976
$scope = $this->getRequest()->getParam('scope');
7077
$scopeId = (int)$this->getRequest()->getParam('scope_id');
@@ -73,7 +80,7 @@ public function execute()
7380
try {
7481
$designConfigData = $this->configFactory->create($scope, $scopeId, $data);
7582
$this->designConfigRepository->save($designConfigData);
76-
$this->messageManager->addSuccess(__('You saved the configuration.'));
83+
$this->messageManager->addSuccessMessage(__('You saved the configuration.'));
7784

7885
$this->dataPersistor->clear('theme_design_config');
7986

@@ -86,10 +93,10 @@ public function execute()
8693
} catch (LocalizedException $e) {
8794
$messages = explode("\n", $e->getMessage());
8895
foreach ($messages as $message) {
89-
$this->messageManager->addError(__('%1', $message));
96+
$this->messageManager->addErrorMessage(__('%1', $message));
9097
}
9198
} catch (\Exception $e) {
92-
$this->messageManager->addException(
99+
$this->messageManager->addExceptionMessage(
93100
$e,
94101
__('Something went wrong while saving this configuration:') . ' ' . $e->getMessage()
95102
);

app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/Design/Config/SaveTest.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,13 @@ public function setUp()
6262
'',
6363
false
6464
);
65-
$this->request = $this->getMockForAbstractClass(
66-
\Magento\Framework\App\RequestInterface::class,
67-
[],
68-
'',
69-
false,
70-
false,
71-
true,
72-
['getFiles', 'getParam', 'getParams']
73-
);
65+
$this->request = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
66+
->disableOriginalConstructor()->getMock();
67+
68+
$this->request->expects($this->atLeastOnce())
69+
->method('isPost')
70+
->willReturn(true);
71+
7472
$this->context = $objectManager->getObject(
7573
\Magento\Backend\App\Action\Context::class,
7674
[
@@ -138,7 +136,7 @@ public function testSave()
138136
->method('save')
139137
->with($this->designConfig);
140138
$this->messageManager->expects($this->once())
141-
->method('addSuccess')
139+
->method('addSuccessMessage')
142140
->with(__('You saved the configuration.'));
143141
$this->dataPersistor->expects($this->once())
144142
->method('clear')
@@ -194,7 +192,7 @@ public function testSaveWithLocalizedException()
194192
->with($this->designConfig)
195193
->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('Exception message')));
196194
$this->messageManager->expects($this->once())
197-
->method('addError')
195+
->method('addErrorMessage')
198196
->with(__('Exception message')->render());
199197

200198
$this->dataPersistor->expects($this->once())
@@ -249,7 +247,7 @@ public function testSaveWithException()
249247
->with($this->designConfig)
250248
->willThrowException($exception);
251249
$this->messageManager->expects($this->once())
252-
->method('addException')
250+
->method('addExceptionMessage')
253251
->with($exception, 'Something went wrong while saving this configuration: Exception message');
254252

255253
$this->dataPersistor->expects($this->once())

0 commit comments

Comments
 (0)