Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
aba1cd8b EM |
2 | |
3 | /** | |
4 | * Class Contact | |
5 | */ | |
6a488035 TO |
6 | class Contact extends CiviUnitTestCase { |
7 | /** | |
8 | * Helper function to create | |
9 | * a contact | |
10 | * | |
2a6da8d7 EM |
11 | * @param $params |
12 | * | |
13 | * @return int $contactID id of created contact | |
6a488035 TO |
14 | */ |
15 | 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 | * | |
2a6da8d7 EM |
25 | * @param null $params |
26 | * @return int $contactID id of created Individual | |
6a488035 TO |
27 | */ |
28 | 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 | * | |
2a6da8d7 EM |
47 | * @param null $params |
48 | * @return mixed $contactID id of created Household | |
6a488035 TO |
49 | */ |
50 | 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 | * | |
2a6da8d7 EM |
68 | * @param null $params |
69 | * @return mixed $contactID id of created Organisation | |
6a488035 TO |
70 | */ |
71 | 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 id of the contact to delete | |
89 | * @return boolean true if contact deleted, false otherwise | |
90 | */ | |
91 | static function delete($contactID) { | |
92 | require_once 'CRM/Contact/BAO/Contact.php'; | |
93 | return CRM_Contact_BAO_Contact::deleteContact($contactID); | |
94 | } | |
95 | } |