]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/SugarTestAccountUtilities.php
Added unit tests.
[Github/sugarcrm.git] / tests / SugarTestAccountUtilities.php
1 <?php
2 require_once 'modules/Accounts/Account.php';
3
4 class SugarTestAccountUtilities
5 {
6     private static $_createdAccounts = array();
7
8     private function __construct() {}
9
10     public static function createAccount($id = '') 
11     {
12         $time = mt_rand();
13         $name = 'SugarAccount';
14         $email1 = 'account@sugar.com';
15         $account = new Account();
16         $account->name = $name . $time;
17         $account->email1 = 'account@'. $time. 'sugar.com';
18         if(!empty($id))
19         {
20             $account->new_with_id = true;
21             $account->id = $id;
22         }
23         $account->save();
24         self::$_createdAccounts[] = $account;
25         return $account;
26     }
27
28     public static function setCreatedAccount($account_ids) {
29         foreach($account_ids as $account_id) {
30                 $account = new Account();
31                 $account->id = $account_id;
32                 self::$_createdAccounts[] = $account;
33         } // foreach
34     } // fn
35     
36     public static function removeAllCreatedAccounts() 
37     {
38         $account_ids = self::getCreatedAccountIds();
39         $GLOBALS['db']->query('DELETE FROM accounts WHERE id IN (\'' . implode("', '", $account_ids) . '\')');
40     }
41         
42     public static function getCreatedAccountIds() 
43     {
44         $account_ids = array();
45         foreach (self::$_createdAccounts as $account) {
46             $account_ids[] = $account->id;
47         }
48         return $account_ids;
49     }
50 }
51 ?>