APIv4 - Add test to ensure custom tables are deleted
authorColeman Watts <coleman@civicrm.org>
Mon, 10 May 2021 21:18:58 +0000 (17:18 -0400)
committerColeman Watts <coleman@civicrm.org>
Mon, 10 May 2021 21:18:58 +0000 (17:18 -0400)
tests/phpunit/api/v4/Action/CustomFieldAlterTest.php

index 1e58fc0b17552c1e366ec5667524d6b9e9be4540..76741ebf584bf4386f80ccc4b2a2fb0ea0ab140a 100644 (file)
@@ -162,6 +162,17 @@ class CustomFieldAlterTest extends BaseCustomValueTest {
         ->execute();
     }
 
+    // Check that custom table exists and is then removed when group is deleted
+    $this->assertNotNull(\CRM_Core_DAO::singleValueQuery("SHOW TABLES LIKE '{$customGroup['table_name']}';"));
+
+    CustomField::delete(FALSE)
+      ->addWhere('custom_group_id', '=', $customGroup['id'])
+      ->execute();
+    CustomGroup::delete(FALSE)
+      ->addWhere('id', '=', $customGroup['id'])
+      ->execute();
+    // The table should be gone
+    $this->assertNull(\CRM_Core_DAO::singleValueQuery("SHOW TABLES LIKE '{$customGroup['table_name']}';"));
   }
 
 }