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 23:50:16 +0000 (12:50 +1300)
Change-Id: Iaa10e26dbbe54f7af228a022d74b48f9107528e8

tests/phpunit/CiviTest/CiviUnitTestCase.php

index c7de801ff3ab92b8c4dedec871904389f6c7a52b..ccdc8fafbaf717849a5ba26cf2013e1720517901 100755 (executable)
@@ -2566,7 +2566,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
    */
@@ -2575,6 +2577,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';
     }