Skip to content

Commit 7bad048

Browse files
author
Dmytro Voskoboinikov
committed
Merge branch 'MAGETWO-88600' into 2.3-bugfixes-290618
2 parents 0c2fa6f + 669c0c2 commit 7bad048

File tree

3 files changed

+50
-16
lines changed
  • app/code/Magento/Theme
  • dev/tests/integration/testsuite/Magento/Theme/Controller/Adminhtml/System/Design/Config

3 files changed

+50
-16
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())

dev/tests/integration/testsuite/Magento/Theme/Controller/Adminhtml/System/Design/Config/SaveTest.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
*/
1515
class SaveTest extends AbstractBackendController
1616
{
17+
/**
18+
* @var FormKey
19+
*/
20+
private $formKey;
21+
1722
/**
1823
* @inheritdoc
1924
*/
@@ -24,6 +29,15 @@ class SaveTest extends AbstractBackendController
2429
*/
2530
protected $uri = 'backend/theme/design_config/save';
2631

32+
protected function setUp()
33+
{
34+
parent::setUp();
35+
36+
$this->formKey = $this->_objectManager->get(
37+
FormKey::class
38+
);
39+
}
40+
2741
/**
2842
* Test design configuration save valid values.
2943
*
@@ -89,7 +103,22 @@ private function getRequestParams()
89103
'watermark_swatch_image_imageOpacity' => '',
90104
'watermark_swatch_image_position' => 'stretch',
91105
'scope' => 'default',
92-
'form_key' => $this->_objectManager->get(FormKey::class)->getFormKey(),
106+
'form_key' => $this->formKey->getFormKey(),
93107
];
94108
}
109+
110+
public function testAclHasAccess()
111+
{
112+
$this->getRequest()->setMethod(
113+
\Zend\Http\Request::METHOD_POST
114+
);
115+
116+
$this->getRequest()->setParams(
117+
[
118+
'form_key' => $this->formKey->getFormKey()
119+
]
120+
);
121+
122+
parent::testAclHasAccess();
123+
}
95124
}

0 commit comments

Comments
 (0)