]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Emails/EmailUITest.php
Release 6.2.0
[Github/sugarcrm.git] / tests / modules / Emails / EmailUITest.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
6  * This program is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  * 
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
16  * details.
17  * 
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  * 
23  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25  * 
26  * The interactive user interfaces in modified source and object code versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  * 
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the "Powered by
32  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33  * technical reasons, the Appropriate Legal Notices must display the words
34  * "Powered by SugarCRM".
35  ********************************************************************************/
36
37  
38 require_once('modules/Emails/EmailUI.php');
39
40 class EmailUITest extends Sugar_PHPUnit_Framework_TestCase
41 {
42     private $_folders = null;
43     
44     public function setUp()
45     {
46         global $current_user;
47         $this->_user = SugarTestUserUtilities::createAnonymousUser();
48         $GLOBALS['current_user'] = $this->_user;
49         $this->eui = new EmailUIMock();
50
51         $this->_folders = array();
52                 
53                 $beanList = array();
54                 $beanFiles = array();
55                 require('include/modules.php');
56                 $GLOBALS['beanList'] = $beanList;
57                 $GLOBALS['beanFiles'] = $beanFiles;
58     }
59     
60     public function tearDown()
61     {
62         $GLOBALS['db']->query("DELETE FROM folders_subscriptions WHERE assigned_user_id='{$GLOBALS['current_user']->id}'");
63         foreach ($this->_folders as $f) {
64             $GLOBALS['db']->query("DELETE FROM folders_subscriptions WHERE folder_id='{$f}'");
65             $GLOBALS['db']->query("DELETE FROM folders WHERE id='{$f}'");
66         }
67         
68         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
69         unset($GLOBALS['current_user']);
70         
71         unset($GLOBALS['beanList']);
72         unset($GLOBALS['beanFiles']);
73         $GLOBALS['db']->query("DELETE FROM folders_subscriptions WHERE assigned_user_id='{$this->_user->id}'");
74             
75         foreach ($this->_folders as $f) {
76             $GLOBALS['db']->query("DELETE FROM folders_subscriptions WHERE folder_id='{$f}'");
77             $GLOBALS['db']->query("DELETE FROM folders WHERE id='{$f}'");
78         }
79     }
80
81     /**
82      * Save a SugarFolder 
83      */
84     public function testSaveNewFolder()
85     {
86         $newFolderName = "UNIT_TEST";
87         $rs = $this->eui->saveNewFolder($newFolderName,'Home',0);
88         $newFolderID = $rs['id'];
89         $this->_folders[] = $newFolderID;
90         
91         $sf = new SugarFolder();
92         $sf->retrieve($newFolderID);
93         $this->assertEquals($newFolderName, $sf->name);
94         
95     }
96     
97     /**
98      * Save the user preference for list view order per IE account.
99      *
100      */
101     public function testSaveListViewSortOrder()
102     {
103         $tmpId = create_guid();
104         $folderName = "UNIT_TEST";
105         $sortBy = 'last_name';
106         $dir = "DESC";
107         $rs = $this->eui->saveListViewSortOrder($tmpId,$folderName,$sortBy,$dir);
108         
109         //Check against the saved preferences.
110         $prefs = unserialize($GLOBALS['current_user']->getPreference('folderSortOrder', 'Emails'));
111         $this->assertEquals($sortBy, $prefs[$tmpId][$folderName]['current']['sort']);
112         $this->assertEquals($dir, $prefs[$tmpId][$folderName]['current']['direction']);
113         
114         
115     }
116     public function testGetRelatedEmail()
117     {
118         
119         $account = new Account();
120         $account->name = "emailTestAccount";
121         $account->save(false);
122         
123         $relatedBeanInfo = array('related_bean_id' => $account->id,  "related_bean_type" => "Accounts");
124         
125         //First pass should return a blank query as are no related items
126         $qArray = $this->eui->getRelatedEmail("LBL_DROPDOWN_LIST_ALL", array(), $relatedBeanInfo);
127         $this->assertEquals("", $qArray['query']);
128         
129         //Now create a related Contact
130         $contact = new Contact();
131         $contact->name = "emailTestContact";
132         $contact->account_id = $account->id;
133         $contact->account_name = $account->name;
134         $contact->email1 = "test@test.com";
135         $contact->save(false);
136         
137         //Now we should get a result
138         $qArray = $this->eui->getRelatedEmail("LBL_DROPDOWN_LIST_ALL", array(), $relatedBeanInfo);
139         $r = $account->db->limitQuery($qArray['query'], 0, 25, true);
140         $person = array();
141         $a = $account->db->fetchByAssoc($r);
142         $person['bean_id'] = $a['id'];
143         $person['bean_module'] = $a['module'];
144         $person['email'] = $a['email_address'];
145         
146         //Cleanup
147         $GLOBALS['db']->query("DELETE FROM accounts WHERE id= '{$account->id}'");
148         $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$contact->id}'");
149         
150         $this->assertEquals("test@test.com", $person['email']);
151     }
152     
153     /**
154      * @ticket 29521
155      */
156     public function testLoadQuickCreateModules()
157     {
158         $qArray = $this->eui->_loadQuickCreateModules();
159
160         $this->assertEquals(array('Bugs','Cases','Contacts', 'Leads', 'Tasks'), $qArray);
161     }
162     
163     /**
164      * @ticket 29521
165      */
166     public function testLoadCustomQuickCreateModulesCanMergeModules()
167     {
168         if (file_exists('custom/modules/Emails/metadata/qcmodulesdefs.php')) {
169             copy('custom/modules/Emails/metadata/qcmodulesdefs.php','custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak');
170         }
171         sugar_mkdir("custom/modules/Emails/metadata/",null,true);
172         file_put_contents(
173             'custom/modules/Emails/metadata/qcmodulesdefs.php',
174             '<?php $QCModules[] = "Users"; ?>'
175             );
176         
177         $qArray = $this->eui->_loadQuickCreateModules();
178
179         if (file_exists('custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak')) {
180             copy('custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak','custom/modules/Emails/metadata/qcmodulesdefs.php');
181             unlink('custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak');
182         }
183         else {
184             unlink('custom/modules/Emails/metadata/qcmodulesdefs.php');
185         }
186         
187         $this->assertEquals(array('Bugs','Cases','Contacts', 'Leads', 'Tasks', 'Users'), $qArray);
188     }
189     
190     /**
191      * @ticket 29521
192      */
193     public function testLoadQuickCreateModulesInvalidModule()
194     {
195         if (file_exists('custom/modules/Emails/metadata/qcmodulesdefs.php')) {
196             copy('custom/modules/Emails/metadata/qcmodulesdefs.php','custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak');
197         }
198         sugar_mkdir("custom/modules/Emails/metadata/",null,true);
199         file_put_contents(
200             'custom/modules/Emails/metadata/qcmodulesdefs.php',
201             '<?php $QCModules[] = "EmailUIUnitTest"; ?>'
202             );
203         
204         $qArray = $this->eui->_loadQuickCreateModules();
205
206         if (file_exists('custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak')) {
207             copy('custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak','custom/modules/Emails/metadata/qcmodulesdefs.php');
208             unlink('custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak');
209         }
210         else {
211             unlink('custom/modules/Emails/metadata/qcmodulesdefs.php');
212         }
213         
214         $this->assertEquals(array('Bugs','Cases','Contacts', 'Leads', 'Tasks'), $qArray);
215     }
216     
217     /**
218      * @ticket 29521
219      */
220     public function testLoadQuickCreateModulesCanOverrideDefaultModules()
221     {
222         if (file_exists('custom/modules/Emails/metadata/qcmodulesdefs.php')) {
223             copy('custom/modules/Emails/metadata/qcmodulesdefs.php','custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak');
224         }
225         sugar_mkdir("custom/modules/Emails/metadata/",null,true);
226         file_put_contents(
227             'custom/modules/Emails/metadata/qcmodulesdefs.php',
228             '<?php $QCModules = array("Users"); ?>'
229             );
230         
231         $qArray = $this->eui->_loadQuickCreateModules();
232
233         if (file_exists('custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak')) {
234             copy('custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak','custom/modules/Emails/metadata/qcmodulesdefs.php');
235             unlink('custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak');
236         }
237         else {
238             unlink('custom/modules/Emails/metadata/qcmodulesdefs.php');
239         }
240         
241         $this->assertEquals(array("Users"), $qArray);
242     }
243 }
244
245 class EmailUIMock extends EmailUI
246 {
247     public function _loadQuickCreateModules()
248     {
249         return parent::_loadQuickCreateModules();
250     }
251 }