Test fixes
authorColeman Watts <coleman@civicrm.org>
Wed, 1 Jan 2014 22:10:49 +0000 (14:10 -0800)
committerColeman Watts <coleman@civicrm.org>
Mon, 6 Jan 2014 19:12:27 +0000 (11:12 -0800)
api/v3/utils.php
tests/phpunit/api/v3/GroupContactTest.php

index 4db65b24b7ae16726559528daf4e0268ecb23f9c..02058a38f776be2290f094cc73e1cf59d4d481c9 100644 (file)
@@ -1056,7 +1056,11 @@ function _civicrm_api3_basic_create($bao_name, &$params, $entity = NULL) {
  * @return CRM_Core_DAO|NULL an instance of the BAO
  */
 function _civicrm_api3_basic_create_fallback($bao_name, &$params) {
-  $entityName = CRM_Core_DAO_AllCoreTables::getBriefName(get_parent_class($bao_name));
+  $dao_name = get_parent_class($bao_name);
+  if ($dao_name === 'CRM_Core_DAO' || !$dao_name) {
+    $dao_name = $bao_name;
+  }
+  $entityName = CRM_Core_DAO_AllCoreTables::getBriefName($dao_name);
   if (empty($entityName)) {
     throw new API_Exception("Class \"$bao_name\" does not map to an entity name", "unmapped_class_to_entity", array(
       'class_name' => $bao_name,
@@ -1065,7 +1069,7 @@ function _civicrm_api3_basic_create_fallback($bao_name, &$params) {
   $hook = empty($params['id']) ? 'create' : 'edit';
 
   CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params);
-  $instance = new $bao_name();
+  $instance = new $dao_name();
   $instance->copyValues($params);
   $instance->save();
   CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance);
index 4ad7ea12187cb74304250e735abc177bc556b27a..24c7304620536b4c92ce8950d7fd89c4047ea487 100644 (file)
@@ -34,7 +34,6 @@ class api_v3_GroupContactTest extends CiviUnitTestCase {
   protected $_contactId1;
   protected $_apiversion = 3;
   protected $_groupId1;
-  protected $_groupContactId;
 
   function get_info() {
     return array(
@@ -61,7 +60,6 @@ class api_v3_GroupContactTest extends CiviUnitTestCase {
     );
 
     $result = $this->callAPISuccess('group_contact', 'create', $params);
-    $this->_groupContactId = $result['id'];
 
     $group = array(
       'name' => 'Test Group 2',
@@ -183,13 +181,15 @@ class api_v3_GroupContactTest extends CiviUnitTestCase {
   }
 
   function testDeletePermanent() {
+    $result = $this->callAPISuccess('group_contact', 'get', array('contact_id' => $this->_contactId));
     $params = array(
-      'id' => $this->_groupContactId,
+      'id' => $result['id'],
       'skip_undelete' => TRUE,
     );
     $this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__, __FILE__);
     $result = $this->callAPISuccess('group_contact', 'get', $params);
     $this->assertEquals(0, $result['count'], "in line " . __LINE__);
+    $this->assertArrayNotHasKey('id', $result, "in line " . __LINE__);
   }
 }