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