Skip to content

Commit

Permalink
MAGETWO-91570: [2.2.x] - [Github]Can not save attribute #5907
Browse files Browse the repository at this point in the history
  • Loading branch information
rganin committed Jun 4, 2018
1 parent ac51a3c commit dc1400e
Showing 1 changed file with 99 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Controller\Adminhtml\Product;
use Magento\Framework\Exception\LocalizedException;

/**
* @magentoAppArea adminhtml
Expand Down Expand Up @@ -224,6 +225,104 @@ public function testSaveActionCleanAttributeLabelCache()
$this->assertEquals('new string translation', $this->_translate('string to translate'));
}

/**
* Get attribute data preset.
*
* @return array
*/
private function getLargeOptionsSetAttributeData()
{
return [
'frontend_label' => [
0 => 'testdrop1',
1 => '',
2 => '',
],
'frontend_input' => 'select',
'is_required' => '0',
'update_product_preview_image' => '0',
'use_product_image_for_swatch' => '0',
'visual_swatch_validation' => '',
'visual_swatch_validation_unique' => '',
'text_swatch_validation' => '',
'text_swatch_validation_unique' => '',
'attribute_code' => 'test_many_options',
'is_global' => '0',
'default_value_text' => '',
'default_value_yesno' => '0',
'default_value_date' => '',
'default_value_textarea' => '',
'is_unique' => '0',
'is_used_in_grid' => '1',
'is_visible_in_grid' => '1',
'is_filterable_in_grid' => '1',
'is_searchable' => '0',
'is_comparable' => '0',
'is_filterable' => '0',
'is_filterable_in_search' => '0',
'is_used_for_promo_rules' => '0',
'is_html_allowed_on_front' => '1',
'is_visible_on_front' => '0',
'used_in_product_listing' => '0',
'used_for_sort_by' => '0',
'swatch_input_type' => 'dropdown',
];
}

/**
* Test attribute saving with large amount of options exceeding maximum allowed by max_input_vars limit.
* @return void
*/
public function testLargeOptionsDataSet()
{
$maxInputVars = ini_get('max_input_vars');
// Each option is at least 4 variables array (order, admin value, first store view value, delete flag).
// Set options count to exceed max_input_vars by 100 options (400 variables).
$optionsCount = floor($maxInputVars / 4) + 100;
$attributeData = $this->getLargeOptionsSetAttributeData();
$optionsData = [];
$expectedOptionsLabels = [];
for ($i = 0; $i < $optionsCount; $i++) {
$order = $i + 1;
$expectedOptionLabelOnStoreView = "value_{$i}_store_1";
$expectedOptionsLabels[$i+1] = $expectedOptionLabelOnStoreView;
$optionsData []= "option[order][option_{$i}]={$order}";
$optionsData []= "option[value][option_{$i}][0]=value_{$i}_admin";
$optionsData []= "option[value][option_{$i}][1]={$expectedOptionLabelOnStoreView}";
$optionsData []= "option[delete][option_{$i}=";
}
$attributeData['serialized_options'] = json_encode($optionsData);
$this->getRequest()->setPostValue($attributeData);
$this->dispatch('backend/catalog/product_attribute/save');
$entityTypeId = $this->_objectManager->create(
\Magento\Eav\Model\Entity::class
)->setType(
\Magento\Catalog\Model\Product::ENTITY
)->getTypeId();

/** @var $attribute \Magento\Catalog\Model\ResourceModel\Eav\Attribute */
$attribute = $this->_objectManager->create(
\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class
)->setEntityTypeId(
$entityTypeId
);
try {
$attribute->loadByCode($entityTypeId, 'test_many_options');
$options = $attribute->getOptions();
// assert that all options are saved without truncation
$this->assertEquals(
$optionsCount + 1,
count($options),
'Expected options count does not match (regarding first empty option for non-required attribute)'
);

foreach ($expectedOptionsLabels as $optionOrderNum => $label) {
$this->assertEquals($label, $options[$optionOrderNum]->getLabel(), 'Label does not match expected.');
}
} catch (LocalizedException $e) {
$this->fail('Test failed with exception on attribute model load: ' . $e);
}
}
/**
* Return translation for a string literal belonging to backend area
*
Expand Down

0 comments on commit dc1400e

Please sign in to comment.