@@ -72,6 +72,17 @@ public function tearDown(): void
7272 {
7373 unset($ GLOBALS ['GLPI_IS_COMMAND_LINE ' ], $ _SERVER ['REMOTE_ADDR ' ]);
7474
75+ // A purge with an oversized name fails on DROP TABLE and leaks the container, even when the test failed before restoring it
76+ /** @var DBmysql $DB */
77+ global $ DB ;
78+ foreach (self ::$ createdContainers as $ container ) {
79+ $ DB ->update (
80+ PluginFieldsContainer ::getTable (),
81+ ['name ' => $ container ->fields ['name ' ]],
82+ ['id ' => $ container ->getID (), 'name ' => str_repeat ('a ' , 100 )],
83+ );
84+ }
85+
7586 $ this ->tearDownFieldTest ();
7687 GLPITestCase ::tearDown ();
7788 }
@@ -789,7 +800,6 @@ public function testRenameOversizedContainerFailsWhenNameIsStillTooLong(): void
789800 'entities_id ' => 0 ,
790801 'is_recursive ' => 1 ,
791802 ]);
792- $ short_name = $ container ->fields ['name ' ];
793803
794804 /** @var DBmysql $DB */
795805 global $ DB ;
@@ -803,10 +813,6 @@ public function testRenameOversizedContainerFailsWhenNameIsStillTooLong(): void
803813 $ this ->assertTrue ($ reloaded ->getFromDB ($ container ->getID ()));
804814 $ this ->assertSame (str_repeat ('a ' , 100 ), $ reloaded ->fields ['name ' ]);
805815 $ this ->assertSame (0 , (int ) $ reloaded ->fields ['is_active ' ]);
806-
807- // Restore a table-name-safe value so the deletion done in tearDown does not
808- // itself attempt a DROP TABLE with an over-64-char identifier.
809- $ DB ->update (PluginFieldsContainer ::getTable (), ['name ' => $ short_name ], ['id ' => $ container ->getID ()]);
810816 }
811817
812818 public function testRenameOversizedContainerFailsOnNameCollision (): void
@@ -828,7 +834,6 @@ public function testRenameOversizedContainerFailsOnNameCollision(): void
828834 'entities_id ' => 0 ,
829835 'is_recursive ' => 1 ,
830836 ]);
831- $ short_name = $ container ->fields ['name ' ];
832837
833838 /** @var DBmysql $DB */
834839 global $ DB ;
@@ -841,9 +846,5 @@ public function testRenameOversizedContainerFailsOnNameCollision(): void
841846 $ reloaded = new PluginFieldsContainer ();
842847 $ this ->assertTrue ($ reloaded ->getFromDB ($ container ->getID ()));
843848 $ this ->assertSame (0 , (int ) $ reloaded ->fields ['is_active ' ]);
844-
845- // Restore a table-name-safe value so the deletion done in tearDown does not
846- // itself attempt a DROP TABLE with an over-64-char identifier.
847- $ DB ->update (PluginFieldsContainer ::getTable (), ['name ' => $ short_name ], ['id ' => $ container ->getID ()]);
848849 }
849850}
0 commit comments