Fix v4 api to do custom field delete in tearDown
authorEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 15 Jul 2021 22:44:34 +0000 (10:44 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 15 Jul 2021 22:44:34 +0000 (10:44 +1200)
This existing efforts are wrong because
1) the delete has to go in the tearDown not the clean up
2) it is rigid about the custom group table name - which
will get us into problems as the name can be set and we
should be ensuring that it can in our tests

tests/phpunit/api/v4/Action/BaseCustomValueTest.php
tests/phpunit/api/v4/Action/BasicCustomFieldTest.php

index 29adc87e373db703dd4128207872323b3e4a22d2..9064c9e143eae79c01ab1e82d79f02ad1091d7e4 100644 (file)
@@ -21,6 +21,7 @@ namespace api\v4\Action;
 
 use api\v4\UnitTestCase;
 use api\v4\Traits\TableDropperTrait;
+use Civi\Api4\CustomGroup;
 
 abstract class BaseCustomValueTest extends UnitTestCase {
 
@@ -34,15 +35,16 @@ abstract class BaseCustomValueTest extends UnitTestCase {
    */
   public function setUp(): void {
     $this->setUpOptionCleanup();
-    $cleanup_params = [
-      'tablesToTruncate' => [
-        'civicrm_custom_group',
-        'civicrm_custom_field',
-      ],
-    ];
-
-    $this->dropByPrefix('civicrm_value_my');
-    $this->cleanup($cleanup_params);
+  }
+
+  /**
+   * Delete all created options groups.
+   *
+   * @throws \API_Exception
+   */
+  public function tearDown(): void {
+    CustomGroup::delete(FALSE)->addWhere('id', '>', 0)->execute();
+    parent::tearDown();
   }
 
 }
index e85f816758df2204500f53237908818b882bce86..28565d4d086f6b6da3dba5a385003e5859d816a9 100644 (file)
@@ -30,8 +30,10 @@ use Civi\Api4\RelationshipCache;
  */
 class BasicCustomFieldTest extends BaseCustomValueTest {
 
-  public function testWithSingleField() {
-
+  /**
+   * @throws \API_Exception
+   */
+  public function testWithSingleField(): void {
     $customGroup = CustomGroup::create(FALSE)
       ->addValue('name', 'MyIndividualFields')
       ->addValue('extends', 'Individual')