Skip to content

Commit 1334635

Browse files
author
roman
committed
MAGETWO-97066: Fixed incorrect behavior of catalog attributes actions
1 parent 2419159 commit 1334635

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Delete.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@
66
*/
77
namespace Magento\Catalog\Controller\Adminhtml\Product\Attribute;
88

9+
use Magento\Framework\Exception\NotFoundException;
10+
911
class Delete extends \Magento\Catalog\Controller\Adminhtml\Product\Attribute
1012
{
1113
/**
1214
* @return \Magento\Backend\Model\View\Result\Redirect
15+
* @throws NotFoundException
1316
*/
1417
public function execute()
1518
{
19+
if (!$this->getRequest()->isPost()) {
20+
throw new NotFoundException(__('Page not found'));
21+
}
22+
1623
$id = $this->getRequest()->getParam('attribute_id');
1724
$resultRedirect = $this->resultRedirectFactory->create();
1825
if ($id) {

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Magento\Framework\Registry;
3030
use Magento\Framework\View\LayoutFactory;
3131
use Magento\Framework\View\Result\PageFactory;
32+
use Magento\Framework\Exception\NotFoundException;
3233

3334
/**
3435
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -124,6 +125,10 @@ public function __construct(
124125
*/
125126
public function execute()
126127
{
128+
if (!$this->getRequest()->isPost()) {
129+
throw new NotFoundException(__('Page not found'));
130+
}
131+
127132
try {
128133
$optionData = $this->formDataSerializer->unserialize(
129134
$this->getRequest()->getParam('serialized_options', '[]')

dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/AttributeTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function testWrongFrontendInput()
2323
'frontend_input' => 'some_input',
2424
];
2525
$this->getRequest()->setPostValue($postData);
26+
$this->getRequest()->setMethod('POST');
2627
$this->dispatch('backend/catalog/product_attribute/save');
2728
$this->assertEquals(302, $this->getResponse()->getHttpResponseCode());
2829
$this->assertContains(
@@ -48,6 +49,7 @@ public function testWithPopup()
4849
'new_attribute_set_name' => 'new_attribute_set',
4950
];
5051
$this->getRequest()->setPostValue($postData);
52+
$this->getRequest()->setMethod('POST');
5153
$this->dispatch('backend/catalog/product_attribute/save');
5254
$this->assertEquals(302, $this->getResponse()->getHttpResponseCode());
5355
$this->assertContains(
@@ -67,6 +69,7 @@ public function testWithPopup()
6769
public function testWithExceptionWhenSaveAttribute()
6870
{
6971
$postData = $this->_getAttributeData() + ['attribute_id' => 0, 'frontend_input' => 'boolean'];
72+
$this->getRequest()->setMethod('POST');
7073
$this->getRequest()->setPostValue($postData);
7174
$this->dispatch('backend/catalog/product_attribute/save');
7275
$this->assertEquals(302, $this->getResponse()->getHttpResponseCode());
@@ -85,6 +88,7 @@ public function testWithExceptionWhenSaveAttribute()
8588
public function testWrongAttributeId()
8689
{
8790
$postData = $this->_getAttributeData() + ['attribute_id' => 100500];
91+
$this->getRequest()->setMethod('POST');
8892
$this->getRequest()->setPostValue($postData);
8993
$this->dispatch('backend/catalog/product_attribute/save');
9094
$this->assertEquals(302, $this->getResponse()->getHttpResponseCode());
@@ -110,6 +114,7 @@ public function testAttributeWithoutId()
110114
'set' => 4,
111115
'frontend_input' => 'boolean',
112116
];
117+
$this->getRequest()->setMethod('POST');
113118
$this->getRequest()->setPostValue($postData);
114119
$this->dispatch('backend/catalog/product_attribute/save');
115120
$this->assertEquals(302, $this->getResponse()->getHttpResponseCode());
@@ -132,6 +137,7 @@ public function testWrongAttributeCode()
132137
{
133138
$postData = $this->_getAttributeData() + ['attribute_code' => '_()&&&?'];
134139
$this->getRequest()->setPostValue($postData);
140+
$this->getRequest()->setMethod('POST');
135141
$this->dispatch('backend/catalog/product_attribute/save');
136142
$this->assertEquals(302, $this->getResponse()->getHttpResponseCode());
137143
$this->assertContains(
@@ -157,6 +163,7 @@ public function testAttributeWithoutEntityTypeId()
157163
{
158164
$postData = $this->_getAttributeData() + ['attribute_id' => '2', 'new_attribute_set_name' => ' '];
159165
$this->getRequest()->setPostValue($postData);
166+
$this->getRequest()->setMethod('POST');
160167
$this->dispatch('backend/catalog/product_attribute/save');
161168
$this->assertEquals(302, $this->getResponse()->getHttpResponseCode());
162169
$this->assertContains(
@@ -172,6 +179,7 @@ public function testSaveActionApplyToDataSystemAttribute()
172179
{
173180
$postData = $this->_getAttributeData() + ['attribute_id' => '2'];
174181
$this->getRequest()->setPostValue($postData);
182+
$this->getRequest()->setMethod('POST');
175183
$this->dispatch('backend/catalog/product_attribute/save');
176184
$model = $this->_objectManager->create(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class);
177185
$model->load($postData['attribute_id']);
@@ -185,6 +193,7 @@ public function testSaveActionApplyToDataUserDefinedAttribute()
185193
{
186194
$postData = $this->_getAttributeData() + ['attribute_id' => '1'];
187195
$this->getRequest()->setPostValue($postData);
196+
$this->getRequest()->setMethod('POST');
188197
$this->dispatch('backend/catalog/product_attribute/save');
189198
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $model */
190199
$model = $this->_objectManager->create(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class);
@@ -218,6 +227,7 @@ public function testSaveActionCleanAttributeLabelCache()
218227
$this->assertEquals('predefined string translation', $this->_translate('string to translate'));
219228
$string->saveTranslate('string to translate', 'new string translation');
220229
$postData = $this->_getAttributeData() + ['attribute_id' => 1];
230+
$this->getRequest()->setMethod('POST');
221231
$this->getRequest()->setPostValue($postData);
222232
$this->dispatch('backend/catalog/product_attribute/save');
223233
$this->assertEquals('new string translation', $this->_translate('string to translate'));
@@ -293,6 +303,7 @@ public function testLargeOptionsDataSet()
293303
$optionsData[] = http_build_query($optionRowData);
294304
}
295305
$attributeData['serialized_options'] = json_encode($optionsData);
306+
$this->getRequest()->setMethod('POST');
296307
$this->getRequest()->setPostValue($attributeData);
297308
$this->dispatch('backend/catalog/product_attribute/save');
298309
$entityTypeId = $this->_objectManager->create(

0 commit comments

Comments
 (0)