99use Magento \Catalog \Test \Fixture \Attribute as AttributeFixture ;
1010use Magento \Catalog \Test \Fixture \Product as ProductFixture ;
1111use Magento \Framework \ObjectManagerInterface ;
12+ use Magento \Store \Model \StoreManagerInterface ;
1213use Magento \TestFramework \Eav \Model \GetAttributeSetByName ;
1314use Magento \TestFramework \Fixture \AppArea ;
1415use Magento \TestFramework \Fixture \AppIsolation ;
@@ -44,6 +45,11 @@ class ProductTest extends TestCase
4445 */
4546 private $ objectManager ;
4647
48+ /**
49+ * @var StoreManagerInterface
50+ */
51+ private $ storeManager ;
52+
4753 /**
4854 * @inheritdoc
4955 */
@@ -53,6 +59,8 @@ protected function setUp(): void
5359
5460 $ this ->productRepository = $ this ->objectManager ->create (ProductRepositoryInterface::class);
5561 $ this ->model = $ this ->objectManager ->create (Product::class);
62+
63+ $ this ->storeManager = $ this ->objectManager ->create (StoreManagerInterface::class);
5664 }
5765
5866 /**
@@ -213,4 +221,57 @@ public function testChangeAttributeSet()
213221 $ attribute = $ this ->model ->getAttributeRawValue ($ product ->getId (), $ attributeCode , 1 );
214222 $ this ->assertEmpty ($ attribute );
215223 }
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+ }
216277}
0 commit comments