Skip to content

Commit d7954d6

Browse files
Dmytro Voskoboinikovaakimov
authored andcommitted
MAGETWO-88602: Incorect Design Configuration
1 parent 508def8 commit d7954d6

File tree

2 files changed

+18
-16
lines changed
  • app/code/Magento/Theme

2 files changed

+18
-16
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Theme\Controller\Adminhtml\Design\Config;
78

89
use Magento\Backend\App\Action;
@@ -68,9 +69,12 @@ public function execute()
6869
$data = $this->getRequestData();
6970

7071
try {
72+
if (!$this->getRequest()->isPost()) {
73+
throw new LocalizedException(__('Wrong request.'));
74+
}
7175
$designConfigData = $this->configFactory->create($scope, $scopeId, $data);
7276
$this->designConfigRepository->save($designConfigData);
73-
$this->messageManager->addSuccess(__('You saved the configuration.'));
77+
$this->messageManager->addSuccessMessage(__('You saved the configuration.'));
7478

7579
$this->dataPersistor->clear('theme_design_config');
7680

@@ -83,10 +87,10 @@ public function execute()
8387
} catch (LocalizedException $e) {
8488
$messages = explode("\n", $e->getMessage());
8589
foreach ($messages as $message) {
86-
$this->messageManager->addError(__('%1', $message));
90+
$this->messageManager->addErrorMessage(__('%1', $message));
8791
}
8892
} catch (\Exception $e) {
89-
$this->messageManager->addException(
93+
$this->messageManager->addExceptionMessage(
9094
$e,
9195
__('Something went wrong while saving this configuration:') . ' ' . $e->getMessage()
9296
);
@@ -110,7 +114,7 @@ protected function getRequestData()
110114
$this->getRequest()->getFiles()->toArray()
111115
);
112116
$data = array_filter($data, function ($param) {
113-
return isset($param['error']) && $param['error'] > 0 ? false : true;
117+
return !(isset($param['error']) && $param['error'] > 0);
114118
});
115119
return $data;
116120
}

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
@@ -71,15 +71,13 @@ public function setUp()
7171
'',
7272
false
7373
);
74-
$this->request = $this->getMockForAbstractClass(
75-
'Magento\Framework\App\RequestInterface',
76-
[],
77-
'',
78-
false,
79-
false,
80-
true,
81-
['getFiles', 'getParam', 'getParams']
82-
);
74+
$this->request = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
75+
->disableOriginalConstructor()->getMock();
76+
77+
$this->request->expects($this->atLeastOnce())
78+
->method('isPost')
79+
->willReturn(true);
80+
8381
$this->context = $objectManager->getObject(
8482
'Magento\Backend\App\Action\Context',
8583
[
@@ -147,7 +145,7 @@ public function testSave()
147145
->method('save')
148146
->with($this->designConfig);
149147
$this->messageManager->expects($this->once())
150-
->method('addSuccess')
148+
->method('addSuccessMessage')
151149
->with(__('You saved the configuration.'));
152150
$this->dataPersistor->expects($this->once())
153151
->method('clear')
@@ -203,7 +201,7 @@ public function testSaveWithLocalizedException()
203201
->with($this->designConfig)
204202
->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('Exception message')));
205203
$this->messageManager->expects($this->once())
206-
->method('addError')
204+
->method('addErrorMessage')
207205
->with(__('Exception message')->render());
208206

209207
$this->dataPersistor->expects($this->once())
@@ -258,7 +256,7 @@ public function testSaveWithException()
258256
->with($this->designConfig)
259257
->willThrowException($exception);
260258
$this->messageManager->expects($this->once())
261-
->method('addException')
259+
->method('addExceptionMessage')
262260
->with($exception, 'Something went wrong while saving this configuration: Exception message');
263261

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

0 commit comments

Comments
 (0)