]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Emails/EmailUITest.php
Added unit tests.
[Github/sugarcrm.git] / tests / modules / Emails / EmailUITest.php
1 <?php
2 require_once('modules/Emails/EmailUI.php');
3
4 class EmailUITest extends Sugar_PHPUnit_Framework_TestCase
5 {
6     private $_folders = null;
7     
8     public function setUp()
9     {
10         $beanList = array();
11         $beanFiles = array();
12         require('include/modules.php');
13         $GLOBALS['beanList'] = $beanList;
14         $GLOBALS['beanFiles'] = $beanFiles;
15         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
16         $this->eui = new EmailUI();
17         $this->_folders = array();
18     }
19     
20     public function tearDown()
21     {
22         $GLOBALS['db']->query("DELETE FROM folders_subscriptions WHERE assigned_user_id='{$GLOBALS['current_user']->id}'");
23         foreach ($this->_folders as $f) {
24             $GLOBALS['db']->query("DELETE FROM folders_subscriptions WHERE folder_id='{$f}'");
25             $GLOBALS['db']->query("DELETE FROM folders WHERE id='{$f}'");
26         }
27         
28         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
29         unset($GLOBALS['current_user']);
30         unset($GLOBALS['beanFiles']);
31         unset($GLOBALS['beanList']);
32     }
33
34     /**
35      * Save a SugarFolder 
36      */
37     public function testSaveNewFolder()
38     {
39         $newFolderName = "UNIT_TEST";
40         $rs = $this->eui->saveNewFolder($newFolderName,'Home',0);
41         $newFolderID = $rs['id'];
42         $this->_folders[] = $newFolderID;
43         
44         $sf = new SugarFolder();
45         $sf->retrieve($newFolderID);
46         $this->assertEquals($newFolderName, $sf->name);
47         
48     }
49     
50     /**
51      * Save the user preference for list view order per IE account.
52      *
53      */
54     public function testSaveListViewSortOrder()
55     {
56         $tmpId = create_guid();
57         $folderName = "UNIT_TEST";
58         $sortBy = 'last_name';
59         $dir = "DESC";
60         $rs = $this->eui->saveListViewSortOrder($tmpId,$folderName,$sortBy,$dir);
61         
62         //Check against the saved preferences.
63         $prefs = unserialize($GLOBALS['current_user']->getPreference('folderSortOrder', 'Emails'));
64         $this->assertEquals($sortBy, $prefs[$tmpId][$folderName]['current']['sort']);
65         $this->assertEquals($dir, $prefs[$tmpId][$folderName]['current']['direction']);
66         
67         
68     }
69     public function testGetRelatedEmail()
70     {
71         
72         $account = new Account();
73         $account->name = "emailTestAccount";
74         $account->save(false);
75         
76         $relatedBeanInfo = array('related_bean_id' => $account->id,  "related_bean_type" => "Accounts");
77         
78         //First pass should return a blank query as are no related items
79         $qArray = $this->eui->getRelatedEmail("LBL_DROPDOWN_LIST_ALL", array(), $relatedBeanInfo);
80         $this->assertEquals("", $qArray['query']);
81         
82         //Now create a related Contact
83         $contact = new Contact();
84         $contact->name = "emailTestContact";
85         $contact->account_id = $account->id;
86         $contact->account_name = $account->name;
87         $contact->email1 = "test@test.com";
88         $contact->save(false);
89         
90         //Now we should get a result
91         $qArray = $this->eui->getRelatedEmail("LBL_DROPDOWN_LIST_ALL", array(), $relatedBeanInfo);
92         $r = $account->db->limitQuery($qArray['query'], 0, 25, true);
93         $person = array();
94         $a = $account->db->fetchByAssoc($r);
95         $person['bean_id'] = $a['id'];
96         $person['bean_module'] = $a['module'];
97         $person['email'] = $a['email_address'];
98         
99         $this->assertEquals("test@test.com", $person['email']);
100         
101         //Cleanup
102         $contact->deleted = true;
103         $contact->save(false);
104         $account->deleted = true;
105         $account->save(false);
106         
107     }
108 }