Skip to content

Commit dc1400e

Browse files
committed
MAGETWO-91570: [2.2.x] - [Github]Can not save attribute #5907
1 parent ac51a3c commit dc1400e

File tree

1 file changed

+99
-0
lines changed
  • dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product

1 file changed

+99
-0
lines changed

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

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento\Catalog\Controller\Adminhtml\Product;
7+
use Magento\Framework\Exception\LocalizedException;
78

89
/**
910
* @magentoAppArea adminhtml
@@ -224,6 +225,104 @@ public function testSaveActionCleanAttributeLabelCache()
224225
$this->assertEquals('new string translation', $this->_translate('string to translate'));
225226
}
226227

228+
/**
229+
* Get attribute data preset.
230+
*
231+
* @return array
232+
*/
233+
private function getLargeOptionsSetAttributeData()
234+
{
235+
return [
236+
'frontend_label' => [
237+
0 => 'testdrop1',
238+
1 => '',
239+
2 => '',
240+
],
241+
'frontend_input' => 'select',
242+
'is_required' => '0',
243+
'update_product_preview_image' => '0',
244+
'use_product_image_for_swatch' => '0',
245+
'visual_swatch_validation' => '',
246+
'visual_swatch_validation_unique' => '',
247+
'text_swatch_validation' => '',
248+
'text_swatch_validation_unique' => '',
249+
'attribute_code' => 'test_many_options',
250+
'is_global' => '0',
251+
'default_value_text' => '',
252+
'default_value_yesno' => '0',
253+
'default_value_date' => '',
254+
'default_value_textarea' => '',
255+
'is_unique' => '0',
256+
'is_used_in_grid' => '1',
257+
'is_visible_in_grid' => '1',
258+
'is_filterable_in_grid' => '1',
259+
'is_searchable' => '0',
260+
'is_comparable' => '0',
261+
'is_filterable' => '0',
262+
'is_filterable_in_search' => '0',
263+
'is_used_for_promo_rules' => '0',
264+
'is_html_allowed_on_front' => '1',
265+
'is_visible_on_front' => '0',
266+
'used_in_product_listing' => '0',
267+
'used_for_sort_by' => '0',
268+
'swatch_input_type' => 'dropdown',
269+
];
270+
}
271+
272+
/**
273+
* Test attribute saving with large amount of options exceeding maximum allowed by max_input_vars limit.
274+
* @return void
275+
*/
276+
public function testLargeOptionsDataSet()
277+
{
278+
$maxInputVars = ini_get('max_input_vars');
279+
// Each option is at least 4 variables array (order, admin value, first store view value, delete flag).
280+
// Set options count to exceed max_input_vars by 100 options (400 variables).
281+
$optionsCount = floor($maxInputVars / 4) + 100;
282+
$attributeData = $this->getLargeOptionsSetAttributeData();
283+
$optionsData = [];
284+
$expectedOptionsLabels = [];
285+
for ($i = 0; $i < $optionsCount; $i++) {
286+
$order = $i + 1;
287+
$expectedOptionLabelOnStoreView = "value_{$i}_store_1";
288+
$expectedOptionsLabels[$i+1] = $expectedOptionLabelOnStoreView;
289+
$optionsData []= "option[order][option_{$i}]={$order}";
290+
$optionsData []= "option[value][option_{$i}][0]=value_{$i}_admin";
291+
$optionsData []= "option[value][option_{$i}][1]={$expectedOptionLabelOnStoreView}";
292+
$optionsData []= "option[delete][option_{$i}=";
293+
}
294+
$attributeData['serialized_options'] = json_encode($optionsData);
295+
$this->getRequest()->setPostValue($attributeData);
296+
$this->dispatch('backend/catalog/product_attribute/save');
297+
$entityTypeId = $this->_objectManager->create(
298+
\Magento\Eav\Model\Entity::class
299+
)->setType(
300+
\Magento\Catalog\Model\Product::ENTITY
301+
)->getTypeId();
302+
303+
/** @var $attribute \Magento\Catalog\Model\ResourceModel\Eav\Attribute */
304+
$attribute = $this->_objectManager->create(
305+
\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class
306+
)->setEntityTypeId(
307+
$entityTypeId
308+
);
309+
try {
310+
$attribute->loadByCode($entityTypeId, 'test_many_options');
311+
$options = $attribute->getOptions();
312+
// assert that all options are saved without truncation
313+
$this->assertEquals(
314+
$optionsCount + 1,
315+
count($options),
316+
'Expected options count does not match (regarding first empty option for non-required attribute)'
317+
);
318+
319+
foreach ($expectedOptionsLabels as $optionOrderNum => $label) {
320+
$this->assertEquals($label, $options[$optionOrderNum]->getLabel(), 'Label does not match expected.');
321+
}
322+
} catch (LocalizedException $e) {
323+
$this->fail('Test failed with exception on attribute model load: ' . $e);
324+
}
325+
}
227326
/**
228327
* Return translation for a string literal belonging to backend area
229328
*

0 commit comments

Comments
 (0)