4444use PluginFieldsContainer ;
4545use PluginFieldsDropdown ;
4646use PluginFieldsField ;
47+ use PluginFieldsToolbox ;
4748use Session ;
4849use Ticket ;
4950use UserEmail ;
@@ -330,17 +331,18 @@ public function testRenameOversizedContainerSucceeds(): void
330331 global $ DB ;
331332 $ DB ->update (PluginFieldsContainer ::getTable (), ['name ' => str_repeat ('a ' , 100 )], ['id ' => $ container ->getID ()]);
332333
333- $ new_name = 'Renamed ' . str_replace ('- ' , '' , $ this ->getUniqueString ());
334+ $ new_name = 'Renamed ' . str_replace ('- ' , '' , $ this ->getUniqueString ());
335+ $ expected_new_name = (new PluginFieldsToolbox ())->getSystemNameFromLabel ($ new_name );
334336
335337 $ result = PluginFieldsContainer ::renameOversizedContainer ($ container ->getID (), $ new_name );
336338 $ this ->assertTrue ($ result );
337339
338340 $ reloaded = new PluginFieldsContainer ();
339341 $ this ->assertTrue ($ reloaded ->getFromDB ($ container ->getID ()));
340- $ this ->assertSame ($ new_name , $ reloaded ->fields ['name ' ]);
342+ $ this ->assertSame ($ expected_new_name , $ reloaded ->fields ['name ' ]);
341343 $ this ->assertSame (1 , (int ) $ reloaded ->fields ['is_active ' ]);
342344
343- $ table = getTableForItemType (PluginFieldsContainer ::getClassname (Computer::class, $ new_name ));
345+ $ table = getTableForItemType (PluginFieldsContainer ::getClassname (Computer::class, $ expected_new_name ));
344346 $ this ->assertTrue ($ DB ->tableExists ($ table ));
345347
346348 // The reactivated container must be genuinely usable, not just flagged active.
@@ -440,16 +442,24 @@ public function testRenameOversizedContainerFailsWhenNameIsStillTooLong(): void
440442 'entities_id ' => 0 ,
441443 'is_recursive ' => 1 ,
442444 ]);
443- $ original_name = $ container ->fields ['name ' ];
445+ $ short_name = $ container ->fields ['name ' ];
446+
447+ /** @var DBmysql $DB */
448+ global $ DB ;
449+ $ DB ->update (PluginFieldsContainer ::getTable (), ['name ' => str_repeat ('a ' , 100 )], ['id ' => $ container ->getID ()]);
444450
445451 $ result = PluginFieldsContainer ::renameOversizedContainer ($ container ->getID (), str_repeat ('a ' , 100 ));
446452
447453 $ this ->assertFalse ($ result );
448454
449455 $ reloaded = new PluginFieldsContainer ();
450456 $ this ->assertTrue ($ reloaded ->getFromDB ($ container ->getID ()));
451- $ this ->assertSame ($ original_name , $ reloaded ->fields ['name ' ]);
457+ $ this ->assertSame (str_repeat ( ' a ' , 100 ) , $ reloaded ->fields ['name ' ]);
452458 $ this ->assertSame (0 , (int ) $ reloaded ->fields ['is_active ' ]);
459+
460+ // Restore a table-name-safe value so the deletion done in tearDown does not
461+ // itself attempt a DROP TABLE with an over-64-char identifier.
462+ $ DB ->update (PluginFieldsContainer ::getTable (), ['name ' => $ short_name ], ['id ' => $ container ->getID ()]);
453463 }
454464
455465 public function testRenameOversizedContainerFailsOnNameCollision (): void
@@ -471,6 +481,11 @@ public function testRenameOversizedContainerFailsOnNameCollision(): void
471481 'entities_id ' => 0 ,
472482 'is_recursive ' => 1 ,
473483 ]);
484+ $ short_name = $ container ->fields ['name ' ];
485+
486+ /** @var DBmysql $DB */
487+ global $ DB ;
488+ $ DB ->update (PluginFieldsContainer ::getTable (), ['name ' => str_repeat ('a ' , 100 )], ['id ' => $ container ->getID ()]);
474489
475490 $ result = PluginFieldsContainer ::renameOversizedContainer ($ container ->getID (), $ existing ->fields ['name ' ]);
476491
@@ -479,5 +494,9 @@ public function testRenameOversizedContainerFailsOnNameCollision(): void
479494 $ reloaded = new PluginFieldsContainer ();
480495 $ this ->assertTrue ($ reloaded ->getFromDB ($ container ->getID ()));
481496 $ this ->assertSame (0 , (int ) $ reloaded ->fields ['is_active ' ]);
497+
498+ // Restore a table-name-safe value so the deletion done in tearDown does not
499+ // itself attempt a DROP TABLE with an over-64-char identifier.
500+ $ DB ->update (PluginFieldsContainer ::getTable (), ['name ' => $ short_name ], ['id ' => $ container ->getID ()]);
482501 }
483502}
0 commit comments