|
4 | 4 | * See COPYING.txt for license details.
|
5 | 5 | */
|
6 | 6 | namespace Magento\Catalog\Controller\Adminhtml\Product;
|
| 7 | +use Magento\Framework\Exception\LocalizedException; |
7 | 8 |
|
8 | 9 | /**
|
9 | 10 | * @magentoAppArea adminhtml
|
@@ -224,6 +225,104 @@ public function testSaveActionCleanAttributeLabelCache()
|
224 | 225 | $this->assertEquals('new string translation', $this->_translate('string to translate'));
|
225 | 226 | }
|
226 | 227 |
|
| 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 | + } |
227 | 326 | /**
|
228 | 327 | * Return translation for a string literal belonging to backend area
|
229 | 328 | *
|
|
0 commit comments