CRM-19209 fix regression found when parents param is empty and CRM-18591 fix issue...
authorSeamus Lee <seamuslee001@gmail.com>
Wed, 10 Aug 2016 20:35:35 +0000 (06:35 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Wed, 10 Aug 2016 20:46:42 +0000 (06:46 +1000)
CRM/Contact/BAO/Group.php
CRM/Group/Form/Edit.php
tests/phpunit/api/v3/GroupTest.php
xml/schema/Contact/Group.xml

index a47084315487da0d05d25568cf7af1fa03ce08c3..6fca737351c61c77ae4ef658dd1964778dbacfdc 100644 (file)
@@ -368,9 +368,12 @@ 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,
-            array_keys($params['group_type'])
+            $params['group_type']
           ) . CRM_Core_DAO::VALUE_SEPARATOR;
       }
+      else {
+        $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . $params['group_type'] . CRM_Core_DAO::VALUE_SEPARATOR;
+      }
     }
     else {
       $params['group_type'] = '';
@@ -389,7 +392,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
 
     // CRM-19068.
     // Validate parents parameter when creating group.
-    if (isset($params['parents'])) {
+    if (!empty($params['parents'])) {
       if (is_array($params['parents'])) {
         foreach ($params['parents'] as $parent => $dc) {
           CRM_Utils_Type::validate($parent, 'Integer');
index a6733dea09e3c8587e48707efa1ef8fbf830b963..0557549f96e46f34ba05b1f163e2b7e4b45e5257 100644 (file)
@@ -395,6 +395,17 @@ 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;
+
       $customFields = CRM_Core_BAO_CustomField::getFields('Group');
       $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params,
         $customFields,
index 311e1f93bc22902f4727924ecaf41eaca6b22902..8f126b136103a39321807aacedcf77f250664161 100644 (file)
@@ -128,6 +128,40 @@ class api_v3_GroupTest extends CiviUnitTestCase {
     }
   }
 
+  /**
+   * Test Group create with Group Type and Parent
+   */
+  public function testGroupCreateWithTypeAndParent() {
+    $params = array(
+      'name' => 'Test Group type',
+      'title' => 'Test Group Type',
+      'description' => 'Test Group with Group Type',
+      'is_active' => 1,
+      //check for empty parent
+      'parents' => "",
+      'visibility' => 'Public Pages',
+      'group_type' => array(1, 2),
+    );
+    $result = $this->callAPISuccess('Group', 'create', $params);
+    $group = $result['values'][$result['id']];
+    $this->assertEquals($group['name'], "Test Group type");
+    $this->assertEquals($group['is_active'], 1);
+    $this->assertEquals($group['parents'], "");
+    $this->assertEquals($group['group_type'], $params['group_type']);
+    //assert single value for group_type and parent
+    $params = array_merge($params, array(
+        'name' => 'Test Group 2',
+        'title' => 'Test Group 2',
+        'group_type' => 2,
+        'parents' => $result['id'],
+      )
+    );
+    $result = $this->callAPISuccess('Group', 'create', $params);
+    $group = $result["values"][$result['id']];
+    $this->assertEquals($group['group_type'], array($params['group_type']));
+    $this->assertEquals($group['parents'], $params['parents']);
+  }
+
   public function testGetNonExistingGroup() {
     $params = array();
     $params['title'] = 'No such group Exist';
index 5f09e4147e1184e0dbcc46fde089f630c1fbdb69..fb9c1bd67125de95bb36ce95a47d1919cb3ad444 100644 (file)
     <title>Group Type</title>
     <length>128</length>
     <comment>FK to group type</comment>
+    <pseudoconstant>
+      <optionGroupName>group_type</optionGroupName>
+    </pseudoconstant>
     <add>1.9</add>
   </field>
   <field>