|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Elasticsearch\Catalog\Controller\Adminhtml\Product\Attribute; |
| 9 | + |
| 10 | +use Magento\Catalog\Controller\Adminhtml\Product\Attribute\Save\AbstractSaveAttributeTest; |
| 11 | + |
| 12 | +/** |
| 13 | + * Test cases related to creating attribute and elasticsearch. |
| 14 | + */ |
| 15 | +class SaveTest extends AbstractSaveAttributeTest |
| 16 | +{ |
| 17 | + /** |
| 18 | + * Default POST data for create attribute. |
| 19 | + * |
| 20 | + * @var array |
| 21 | + */ |
| 22 | + private const DEFAULT_ATTRIBUTE_POST_DATA = [ |
| 23 | + 'active_tab' => 'main', |
| 24 | + 'frontend_label' => [ |
| 25 | + '0' => 'Test attribute name', |
| 26 | + ], |
| 27 | + 'frontend_input' => 'select', |
| 28 | + 'is_required' => '0', |
| 29 | + 'attribute_code' => 'filtrable_attribute', |
| 30 | + 'is_global' => '1', |
| 31 | + 'default_value_yesno' => '0', |
| 32 | + 'is_unique' => '0', |
| 33 | + 'is_used_in_grid' => '1', |
| 34 | + 'is_visible_in_grid' => '1', |
| 35 | + 'is_filterable_in_grid' => '1', |
| 36 | + 'is_filterable' => '1', |
| 37 | + 'is_filterable_in_search' => '0', |
| 38 | + 'is_searchable' => '0', |
| 39 | + 'is_comparable' => '0', |
| 40 | + 'is_used_for_promo_rules' => '0', |
| 41 | + 'is_html_allowed_on_front' => '1', |
| 42 | + 'is_visible_on_front' => '0', |
| 43 | + 'used_in_product_listing' => '0', |
| 44 | + ]; |
| 45 | + |
| 46 | + /** |
| 47 | + * @param array $data |
| 48 | + * @param string $errorMessage |
| 49 | + * @dataProvider createAttributeWithErrorDataProvider |
| 50 | + */ |
| 51 | + public function testCreateAttributeWithError(array $data, string $errorMessage): void |
| 52 | + { |
| 53 | + $this->createAttributeUsingDataWithErrorAndAssert( |
| 54 | + array_merge(self::DEFAULT_ATTRIBUTE_POST_DATA, $data), |
| 55 | + $errorMessage |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * @return array |
| 61 | + */ |
| 62 | + public function createAttributeWithErrorDataProvider(): array |
| 63 | + { |
| 64 | + return [ |
| 65 | + 'should not create attribute with reserved code "category_name"' => [ |
| 66 | + [ |
| 67 | + 'attribute_code' => 'category_name' |
| 68 | + ], |
| 69 | + 'The attribute code 'category_name' is reserved by system. ' . |
| 70 | + 'Please try another attribute code' |
| 71 | + ] |
| 72 | + ]; |
| 73 | + } |
| 74 | +} |
0 commit comments