From 57c93d721120d902beea4181ff68272d858dd351 Mon Sep 17 00:00:00 2001 From: Eileen Date: Fri, 3 Jan 2014 16:29:58 +1300 Subject: [PATCH] GroupContactTest fails locally as 'parents' param is incorrectly handled in BAO - presume my set-up must be more restrictive in some way as this doesn't fail on server --- CRM/Contact/BAO/Group.php | 11 ++++++++++- .../phpunit/CRM/Contact/BAO/GroupContactCacheTest.php | 4 +--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CRM/Contact/BAO/Group.php b/CRM/Contact/BAO/Group.php index fb680b7b87..40439e0df8 100644 --- a/CRM/Contact/BAO/Group.php +++ b/CRM/Contact/BAO/Group.php @@ -379,7 +379,16 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { $group = new CRM_Contact_BAO_Group(); $group->copyValues($params); - + //@todo very hacky fix for the fact this function wants to receive 'parents' as an array further down but + // needs it as a separated string for the DB. Preferred approaches are having the copyParams or save fn + // use metadata to translate the array to the appropriate DB type or altering the param in the api layer, + // or at least altering the param in same section as 'group_type' rather than repeating here. However, further down + // we need the $params one to be in it's original form & we are not sure what test coverage we have on that + if(isset($group->parents) && is_array($group->parents)) { + $group->parents = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, + array_keys($group->parents) + ) . CRM_Core_DAO::VALUE_SEPARATOR; + } if (!CRM_Utils_Array::value('id', $params)) { $group->name .= "_tmp"; } diff --git a/tests/phpunit/CRM/Contact/BAO/GroupContactCacheTest.php b/tests/phpunit/CRM/Contact/BAO/GroupContactCacheTest.php index 1d5cc2d0bb..5a34a77e83 100644 --- a/tests/phpunit/CRM/Contact/BAO/GroupContactCacheTest.php +++ b/tests/phpunit/CRM/Contact/BAO/GroupContactCacheTest.php @@ -121,12 +121,10 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { // Add $c1, $c2, $c3 to $child foreach ($deceased as $contact) { - $result = civicrm_api('group_contact', 'create', array( + $result = $this->callAPISuccess('group_contact', 'create', array( 'contact_id' => $contact->id, 'group_id' => $child->id, - 'version' => '3', )); - $this->assertAPISuccess($result); } // GroupContactCache::load() -- 2.25.1