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