9
9
use Magento \Catalog \Test \Fixture \Attribute as AttributeFixture ;
10
10
use Magento \Catalog \Test \Fixture \Product as ProductFixture ;
11
11
use Magento \Framework \ObjectManagerInterface ;
12
+ use Magento \Store \Model \StoreManagerInterface ;
12
13
use Magento \TestFramework \Eav \Model \GetAttributeSetByName ;
13
14
use Magento \TestFramework \Fixture \AppArea ;
14
15
use Magento \TestFramework \Fixture \AppIsolation ;
@@ -44,6 +45,11 @@ class ProductTest extends TestCase
44
45
*/
45
46
private $ objectManager ;
46
47
48
+ /**
49
+ * @var StoreManagerInterface
50
+ */
51
+ private $ storeManager ;
52
+
47
53
/**
48
54
* @inheritdoc
49
55
*/
@@ -53,6 +59,8 @@ protected function setUp(): void
53
59
54
60
$ this ->productRepository = $ this ->objectManager ->create (ProductRepositoryInterface::class);
55
61
$ this ->model = $ this ->objectManager ->create (Product::class);
62
+
63
+ $ this ->storeManager = $ this ->objectManager ->create (StoreManagerInterface::class);
56
64
}
57
65
58
66
/**
@@ -213,4 +221,57 @@ public function testChangeAttributeSet()
213
221
$ attribute = $ this ->model ->getAttributeRawValue ($ product ->getId (), $ attributeCode , 1 );
214
222
$ this ->assertEmpty ($ attribute );
215
223
}
224
+
225
+ /**
226
+ * Test update product custom attributes
227
+ *
228
+ * @return void
229
+ */
230
+ #[
231
+ DataFixture(AttributeFixture::class, ['attribute_code ' => 'first_custom_attribute ' ]),
232
+ DataFixture(AttributeFixture::class, ['attribute_code ' => 'second_custom_attribute ' ]),
233
+ DataFixture(AttributeFixture::class, ['attribute_code ' => 'third_custom_attribute ' ]),
234
+ DataFixture(ProductFixture::class, ['sku ' => 'simple ' ,'media_gallery_entries ' => [[], []]], as: 'product ' )
235
+ ]
236
+
237
+ public function testUpdateCustomerAttributesAutoIncrement ()
238
+ {
239
+ $ resource = $ this ->objectManager ->get (\Magento \Framework \App \ResourceConnection::class);
240
+ $ connection = $ resource ->getConnection ();
241
+ $ currentTableStatus = $ connection ->showTableStatus ('catalog_product_entity_varchar ' );
242
+ $ this ->storeManager ->setCurrentStore ('admin ' );
243
+ $ product = $ this ->productRepository ->get ('simple ' );
244
+ $ product ->setCustomAttribute (
245
+ 'first_custom_attribute ' ,
246
+ 'first attribute '
247
+ );
248
+ $ firstAttributeSavedProduct = $ this ->productRepository ->save ($ product );
249
+ $ currentTableStatusAfterFirstAttrSave = $ connection ->showTableStatus ('catalog_product_entity_varchar ' );
250
+ $ this ->assertSame (
251
+ ((int ) ($ currentTableStatus ['Auto_increment ' ]) + 1 ),
252
+ (int ) $ currentTableStatusAfterFirstAttrSave ['Auto_increment ' ]
253
+ );
254
+
255
+ $ firstAttributeSavedProduct ->setCustomAttribute (
256
+ 'second_custom_attribute ' ,
257
+ 'second attribute '
258
+ );
259
+ $ secondAttributeSavedProduct = $ this ->productRepository ->save ($ firstAttributeSavedProduct );
260
+ $ currentTableStatusAfterSecondAttrSave = $ connection ->showTableStatus ('catalog_product_entity_varchar ' );
261
+ $ this ->assertSame (
262
+ (((int ) $ currentTableStatusAfterFirstAttrSave ['Auto_increment ' ]) + 1 ),
263
+ (int ) $ currentTableStatusAfterSecondAttrSave ['Auto_increment ' ]
264
+ );
265
+
266
+ $ secondAttributeSavedProduct ->setCustomAttribute (
267
+ 'third_custom_attribute ' ,
268
+ 'third attribute '
269
+ );
270
+ $ this ->productRepository ->save ($ secondAttributeSavedProduct );
271
+ $ currentTableStatusAfterThirdAttrSave = $ connection ->showTableStatus ('catalog_product_entity_varchar ' );
272
+ $ this ->assertSame (
273
+ (((int )$ currentTableStatusAfterSecondAttrSave ['Auto_increment ' ]) + 1 ),
274
+ (int ) $ currentTableStatusAfterThirdAttrSave ['Auto_increment ' ]
275
+ );
276
+ }
216
277
}
0 commit comments