Fix group_type param in creating group
authorjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Mon, 26 Dec 2016 06:12:28 +0000 (11:42 +0530)
committerjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Mon, 26 Dec 2016 06:23:13 +0000 (11:53 +0530)
CRM/Contact/BAO/Group.php
CRM/Group/Form/Edit.php
tests/phpunit/api/v3/GroupTest.php

index 69e043be8a2c7b59d9a311d89c550f610af8608f..7741d163e935cf66b566ba43242b902bc39beae3 100644 (file)
@@ -360,7 +360,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
     if (isset($params['group_type'])) {
       if (is_array($params['group_type'])) {
         $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR,
-            $params['group_type']
+            CRM_Utils_Array::convertCheckboxFormatToArray($params['group_type'])
           ) . CRM_Core_DAO::VALUE_SEPARATOR;
       }
       else {
index e3c97df4b6cf61941844901ef0b7200b31c6f5ca..535ceda097e0a2c172996ff50273b7002df48f07 100644 (file)
@@ -380,17 +380,6 @@ WHERE  title = %1
 
       $params['is_reserved'] = CRM_Utils_Array::value('is_reserved', $params, FALSE);
 
-      $groupTypeIds = array();
-      $groupType = CRM_Utils_Array::value('group_type', $params);
-      if (is_array($groupType)) {
-        foreach ($groupType as $type => $selected) {
-          if ($selected) {
-            $groupTypeIds[] = $type;
-          }
-        }
-      }
-      $params['group_type'] = $groupTypeIds;
-
       $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params,
         $this->_id,
         'Group'
index 75aaf8fb0e87d1c75df06a41d23fa2b9aa549bb2..8f02cc2caaa2b6fa29f2b5566c7fcf0205dfd3be 100644 (file)
@@ -149,6 +149,18 @@ class api_v3_GroupTest extends CiviUnitTestCase {
     $this->assertEquals($group['parents'], "");
     $this->assertEquals($group['group_type'], $params['group_type']);
 
+    //Pass group_type param in checkbox format.
+    $params = array_merge($params, array(
+        'name' => 'Test Checkbox Format',
+        'title' => 'Test Checkbox Format',
+        'group_type' => array(2 => 1),
+      )
+    );
+    $result = $this->callAPISuccess('Group', 'create', $params);
+    $group = $result['values'][$result['id']];
+    $this->assertEquals($group['name'], "Test Checkbox Format");
+    $this->assertEquals($group['group_type'], array_keys($params['group_type']));
+
     //assert single value for group_type and parent
     $params = array_merge($params, array(
         'name' => 'Test Group 2',