]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/SugarTestContactUtilities.php
Added unit tests.
[Github/sugarcrm.git] / tests / SugarTestContactUtilities.php
1 <?php
2 require_once 'modules/Contacts/Contact.php';
3
4 class SugarTestContactUtilities
5 {
6     private static $_createdContacts = array();
7
8     private function __construct() {}
9
10     public static function createContact($id = '') 
11     {
12         $time = mt_rand();
13         $first_name = 'SugarContactFirst';
14         $last_name = 'SugarContactLast';
15         $email1 = 'contact@sugar.com';
16         $contact = new Contact();
17         $contact->first_name = $first_name . $time;
18         $contact->last_name = $last_name ;
19         $contact->email1 = 'contact@'. $time. 'sugar.com';
20         if(!empty($id))
21         {
22             $contact->new_with_id = true;
23             $contact->id = $id;
24         }
25         $contact->save();
26         self::$_createdContacts[] = $contact;
27         return $contact;
28     }
29
30     public static function setCreatedContact($contact_ids) {
31         foreach($contact_ids as $contact_id) {
32                 $contact = new Contact();
33                 $contact->id = $contact_id;
34                 self::$_createdContacts[] = $contact;
35         } // foreach
36     } // fn
37     
38     public static function removeAllCreatedContacts() 
39     {
40         $contact_ids = self::getCreatedContactIds();
41         $GLOBALS['db']->query('DELETE FROM contacts WHERE id IN (\'' . implode("', '", $contact_ids) . '\')');
42     }
43     
44     public static function removeCreatedContactsUsersRelationships(){
45         $contact_ids = self::getCreatedContactIds();
46         $GLOBALS['db']->query('DELETE FROM contacts_users WHERE contact_id IN (\'' . implode("', '", $contact_ids) . '\')');
47     }
48     
49     public static function getCreatedContactIds() 
50     {
51         $contact_ids = array();
52         foreach (self::$_createdContacts as $contact) {
53             $contact_ids[] = $contact->id;
54         }
55         return $contact_ids;
56     }
57 }
58 ?>