Add cleanup for option groups to quick cleanup
authoreileen <emcnaughton@wikimedia.org>
Tue, 29 Dec 2015 04:59:38 +0000 (17:59 +1300)
committereileen <emcnaughton@wikimedia.org>
Tue, 29 Dec 2015 21:32:11 +0000 (10:32 +1300)
Change-Id: Iaa10e26dbbe54f7af228a022d74b48f9107528e8

tests/phpunit/CiviTest/CiviUnitTestCase.php

index 1400c9bdffd93d060115c7c1c90b3687ef5dae6f..a6f4e213efb1245deebb222afe2bc10ee1f584b0 100755 (executable)
@@ -2529,7 +2529,9 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * @param $tablesToTruncate
+   * Quick clean by emptying tables created for the test.
+   *
+   * @param array $tablesToTruncate
    * @param bool $dropCustomValueTables
    * @throws \Exception
    */
@@ -2538,6 +2540,12 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
       throw new Exception("CiviUnitTestCase: quickCleanup() is not compatible with useTransaction()");
     }
     if ($dropCustomValueTables) {
+      $optionGroupResult = CRM_Core_DAO::executeQuery('SELECT option_group_id FROM civicrm_custom_field');
+      while ($optionGroupResult->fetch()) {
+        if (!empty($optionGroupResult->option_group_id)) {
+          CRM_Core_DAO::executeQuery('DELETE FROM civicrm_option_group WHERE id = ' . $optionGroupResult->option_group_id);
+        }
+      }
       $tablesToTruncate[] = 'civicrm_custom_group';
       $tablesToTruncate[] = 'civicrm_custom_field';
     }