/** * Test civicrm_contact_add() * * Verify that attempt to create individual contact with only * first and last names succeeds */ function testAddCreateIndividual() { $params = array('first_name' => 'abc1', 'contact_type' => 'Individual', 'last_name' => 'xyz1'); $contact =& civicrm_contact_add($params); $this->assertEquals(0, $contact['is_error'], "In line " . __LINE__ . " error message: " . $contact['error_message']); $this->assertEquals(1, $contact['contact_id'], "In line " . __LINE__); // delete the contact civicrm_contact_delete($contact); }
static function contactID($ufID) { require_once 'api/v2/UFGroup.php'; $contactID = civicrm_uf_match_id_get($ufID); if ($contactID) { return $contactID; } // else create a contact for this user $user = user_load(array('uid' => $ufID)); $params = array('contact_type' => 'Individual', 'email' => $user->mail); require_once 'api/v2/Contact.php'; $values = civicrm_contact_add($params); if ($values['is_error']) { CRM_Core_Error::fatal(); } return $values['contact_id']; }
/** * Private helper function for calling civicrm_contact_add * * @param array parameters for civicrm_contact_add api function call * @return int id of Household created */ private function _contactCreate($params) { require_once 'api/v2/Contact.php'; $result = civicrm_contact_add($params); if (CRM_Utils_Array::value('is_error', $result) || !CRM_Utils_Array::value('contact_id', $result)) { throw new Exception('Could not create test contact.'); } return $result['contact_id']; }