Merge pull request #3204 from GinkgoFJG/CRM-14662
[civicrm-core.git] / tests / phpunit / CiviTest / Contact.php
1 <?php
2 class Contact extends CiviUnitTestCase {
3 /**
4 * Helper function to create
5 * a contact
6 *
7 * @param $params
8 *
9 * @return int $contactID id of created contact
10 */
11 static function create($params) {
12 require_once "CRM/Contact/BAO/Contact.php";
13 $contactID = CRM_Contact_BAO_Contact::createProfileContact($params, CRM_Core_DAO::$_nullArray);
14 return $contactID;
15 }
16
17 /**
18 * Helper function to create
19 * a contact of type Individual
20 *
21 * @param null $params
22 * @return int $contactID id of created Individual
23 */
24 static function createIndividual($params = NULL) {
25 //compose the params, when not passed
26 if (!$params) {
27 $first_name = 'John';
28 $last_name = 'Doe';
29 $contact_source = 'Testing purpose';
30 $params = array(
31 'first_name' => $first_name,
32 'last_name' => $last_name,
33 'contact_source' => $contact_source,
34 );
35 }
36 return self::create($params);
37 }
38
39 /**
40 * Helper function to create
41 * a contact of type Household
42 *
43 * @param null $params
44 * @return mixed $contactID id of created Household
45 */
46 static function createHousehold($params = NULL) {
47 //compose the params, when not passed
48 if (!$params) {
49 $household_name = "John Doe's home";
50 $params = array(
51 'household_name' => $household_name,
52 'contact_type' => 'Household',
53 );
54 }
55 require_once "CRM/Contact/BAO/Contact.php";
56 $household = CRM_Contact_BAO_Contact::create($params);
57 return $household->id;
58 }
59
60 /**
61 * Helper function to create
62 * a contact of type Organisation
63 *
64 * @param null $params
65 * @return mixed $contactID id of created Organisation
66 */
67 static function createOrganisation($params = NULL) {
68 //compose the params, when not passed
69 if (!$params) {
70 $organization_name = "My Organization";
71 $params = array(
72 'organization_name' => $organization_name,
73 'contact_type' => 'Organization',
74 );
75 }
76 require_once "CRM/Contact/BAO/Contact.php";
77 $organization = CRM_Contact_BAO_Contact::create($params);
78 return $organization->id;
79 }
80
81 /**
82 * Helper function to delete a contact
83 *
84 * @param int $contactID id of the contact to delete
85 * @return boolean true if contact deleted, false otherwise
86 */
87 static function delete($contactID) {
88 require_once 'CRM/Contact/BAO/Contact.php';
89 return CRM_Contact_BAO_Contact::deleteContact($contactID);
90 }
91 }