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