[test] - Add test coverage for adjusting custom group weights
authorColeman Watts <coleman@civicrm.org>
Sat, 15 Jan 2022 00:20:01 +0000 (19:20 -0500)
committerColeman Watts <coleman@civicrm.org>
Sat, 15 Jan 2022 00:20:01 +0000 (19:20 -0500)
tests/phpunit/api/v4/Action/BasicCustomFieldTest.php

index 240ce3a9432f0ffe74e283f5e7f500f72c8e7d1e..4cc32bbcf010bbbce27909a2dcd2647f4066d7d1 100644 (file)
@@ -426,8 +426,25 @@ class BasicCustomFieldTest extends BaseCustomValueTest {
       $this->assertEquals(['One' => 1, 'Two' => 2, 'Three' => 3, 'Four' => 4], $getValues($groupName));
     }
 
+    // Testing custom group weights
+
+    $originalControlGroupWeight = $customGroups['controlGroup']['weight'];
+    $originalExperimentalGroupWeight = $customGroups['experimentalGroup']['weight'];
+
     // Ensure default weights were set for custom groups
-    $this->assertEquals($customGroups['controlGroup']['weight'] + 1, $customGroups['experimentalGroup']['weight']);
+    $this->assertEquals($originalControlGroupWeight + 1, $originalExperimentalGroupWeight);
+    // Updating custom group weight
+    $newExperimentalGroupWeight = CustomGroup::update(FALSE)
+      ->addValue('id', $customGroups['experimentalGroup']['id'])
+      ->addValue('weight', $originalControlGroupWeight)
+      ->execute()->first()['weight'];
+    // The other group's weight should have auto-adjusted
+    $newControlGroupWeight = CustomGroup::get(FALSE)
+      ->addWhere('id', '=', $customGroups['controlGroup']['id'])
+      ->execute()->first()['weight'];
+    $this->assertEquals($newExperimentalGroupWeight + 1, $newControlGroupWeight);
+
+    // Testing custom field weights
 
     // Move third option to second position
     CustomField::update(FALSE)