Merge pull request #5446 from atif-shaikh/CRM-14105
[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
14 * $contactID id of created contact
15 */
16 public static function create($params) {
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 *
26 * @param array $params
27 * @return int
28 * $contactID id of created Individual
29 */
30 public static function createIndividual($params = NULL) {
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 *
49 * @param array $params
50 * @return int
51 * id of created Household
52 */
53 public static function createHousehold($params = NULL) {
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 *
71 * @param array $params
72 * @return int
73 * id of created Organisation
74 */
75 public static function createOrganisation($params = NULL) {
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 /**
90 * Helper function to delete a contact.
91 *
92 * @param int $contactID
93 * Id of the contact to delete.
94 * @return bool
95 * true if contact deleted, false otherwise
96 */
97 public static function delete($contactID) {
98 require_once 'CRM/Contact/BAO/Contact.php';
99 return CRM_Contact_BAO_Contact::deleteContact($contactID);
100 }
101
102 }