]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Emails/EmailUITest.php
Release 6.2.3
[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         $this->_user->is_admin = 1;
49         $GLOBALS['current_user'] = $this->_user;
50         $this->eui = new EmailUIMock();
51
52         $this->_folders = array();
53                 
54                 $beanList = array();
55                 $beanFiles = array();
56                 require('include/modules.php');
57                 $GLOBALS['beanList'] = $beanList;
58                 $GLOBALS['beanFiles'] = $beanFiles;
59     }
60     
61     public function tearDown()
62     {
63         $GLOBALS['db']->query("DELETE FROM folders_subscriptions WHERE assigned_user_id='{$GLOBALS['current_user']->id}'");
64         foreach ($this->_folders as $f) {
65             $GLOBALS['db']->query("DELETE FROM folders_subscriptions WHERE folder_id='{$f}'");
66             $GLOBALS['db']->query("DELETE FROM folders WHERE id='{$f}'");
67         }
68         
69         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
70         unset($GLOBALS['current_user']);
71         
72         unset($GLOBALS['beanList']);
73         unset($GLOBALS['beanFiles']);
74         $GLOBALS['db']->query("DELETE FROM folders_subscriptions WHERE assigned_user_id='{$this->_user->id}'");
75             
76         foreach ($this->_folders as $f) {
77             $GLOBALS['db']->query("DELETE FROM folders_subscriptions WHERE folder_id='{$f}'");
78             $GLOBALS['db']->query("DELETE FROM folders WHERE id='{$f}'");
79         }
80     }
81
82     /**
83      * Save a SugarFolder 
84      */
85     public function testSaveNewFolder()
86     {
87         $newFolderName = "UNIT_TEST";
88         $rs = $this->eui->saveNewFolder($newFolderName,'Home',0);
89         $newFolderID = $rs['id'];
90         $this->_folders[] = $newFolderID;
91         
92         $sf = new SugarFolder();
93         $sf->retrieve($newFolderID);
94         $this->assertEquals($newFolderName, $sf->name);
95         
96     }
97
98     /**
99      * Save the user preference for list view order per IE account.
100      *
101      */
102     public function testSaveListViewSortOrder()
103     {
104         $tmpId = create_guid();
105         $folderName = "UNIT_TEST";
106         $sortBy = 'last_name';
107         $dir = "DESC";
108         $rs = $this->eui->saveListViewSortOrder($tmpId,$folderName,$sortBy,$dir);
109         
110         //Check against the saved preferences.
111         $prefs = unserialize($GLOBALS['current_user']->getPreference('folderSortOrder', 'Emails'));
112         $this->assertEquals($sortBy, $prefs[$tmpId][$folderName]['current']['sort']);
113         $this->assertEquals($dir, $prefs[$tmpId][$folderName]['current']['direction']);
114         
115         
116     }
117     public function testGetRelatedEmail()
118     {
119         
120         $account = new Account();
121         $account->name = "emailTestAccount";
122         $account->save(false);
123
124         $relatedBeanInfo = array('related_bean_id' => $account->id,  "related_bean_type" => "Accounts");
125         
126         //First pass should return a blank query as are no related items
127         $qArray = $this->eui->getRelatedEmail("LBL_DROPDOWN_LIST_ALL", array(), $relatedBeanInfo);
128         $this->assertEquals("", $qArray['query']);
129
130         //Now create a related Contact
131         $contact = new Contact();
132         $contact->name = "emailTestContact";
133         $contact->account_id = $account->id;
134         $contact->account_name = $account->name;
135         $contact->email1 = "test@test.com";
136         $contact->save(false);
137
138         //Now we should get a result
139         $qArray = $this->eui->getRelatedEmail("LBL_DROPDOWN_LIST_ALL", array(), $relatedBeanInfo);
140         $r = $account->db->limitQuery($qArray['query'], 0, 25, true);
141         $person = array();
142         $a = $account->db->fetchByAssoc($r);
143         $person['bean_id'] = $a['id'];
144         $person['bean_module'] = $a['module'];
145         $person['email'] = $a['email_address'];
146
147         //Cleanup
148         $GLOBALS['db']->query("DELETE FROM accounts WHERE id= '{$account->id}'");
149         $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$contact->id}'");
150
151         $this->assertEquals("test@test.com", $person['email']);
152     }
153     
154     /**
155      * @ticket 29521
156      */
157     public function testLoadQuickCreateModules()
158     {
159         $qArray = $this->eui->_loadQuickCreateModules();
160
161         $this->assertEquals(array('Bugs','Cases','Contacts', 'Leads', 'Tasks'), $qArray);
162     }
163
164     /**
165      * @ticket 29521
166      */
167     public function testLoadCustomQuickCreateModulesCanMergeModules()
168     {
169         if (file_exists('custom/modules/Emails/metadata/qcmodulesdefs.php')) {
170             copy('custom/modules/Emails/metadata/qcmodulesdefs.php','custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak');
171         }
172         sugar_mkdir("custom/modules/Emails/metadata/",null,true);
173         file_put_contents(
174             'custom/modules/Emails/metadata/qcmodulesdefs.php',
175             '<?php $QCModules[] = "Users"; ?>'
176             );
177         
178         $qArray = $this->eui->_loadQuickCreateModules();
179
180         if (file_exists('custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak')) {
181             copy('custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak','custom/modules/Emails/metadata/qcmodulesdefs.php');
182             unlink('custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak');
183         }
184         else {
185             unlink('custom/modules/Emails/metadata/qcmodulesdefs.php');
186         }
187         
188         $this->assertEquals(array('Bugs','Cases','Contacts', 'Leads', 'Tasks', 'Users'), $qArray);
189     }
190
191     /**
192      * @ticket 29521
193      */
194     public function testLoadQuickCreateModulesInvalidModule()
195     {
196         if (file_exists('custom/modules/Emails/metadata/qcmodulesdefs.php')) {
197             copy('custom/modules/Emails/metadata/qcmodulesdefs.php','custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak');
198         }
199         sugar_mkdir("custom/modules/Emails/metadata/",null,true);
200         file_put_contents(
201             'custom/modules/Emails/metadata/qcmodulesdefs.php',
202             '<?php $QCModules[] = "EmailUIUnitTest"; ?>'
203             );
204         
205         $qArray = $this->eui->_loadQuickCreateModules();
206
207         if (file_exists('custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak')) {
208             copy('custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak','custom/modules/Emails/metadata/qcmodulesdefs.php');
209             unlink('custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak');
210         }
211         else {
212             unlink('custom/modules/Emails/metadata/qcmodulesdefs.php');
213         }
214         
215         $this->assertEquals(array('Bugs','Cases','Contacts', 'Leads', 'Tasks'), $qArray);
216     }
217
218     /**
219      * @ticket 29521
220      */
221     public function testLoadQuickCreateModulesCanOverrideDefaultModules()
222     {
223         if (file_exists('custom/modules/Emails/metadata/qcmodulesdefs.php')) {
224             copy('custom/modules/Emails/metadata/qcmodulesdefs.php','custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak');
225         }
226         sugar_mkdir("custom/modules/Emails/metadata/",null,true);
227         file_put_contents(
228             'custom/modules/Emails/metadata/qcmodulesdefs.php',
229             '<?php $QCModules = array("Users"); ?>'
230             );
231         
232         $qArray = $this->eui->_loadQuickCreateModules();
233
234         if (file_exists('custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak')) {
235             copy('custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak','custom/modules/Emails/metadata/qcmodulesdefs.php');
236             unlink('custom/modules/Emails/metadata/qcmodulesdefs.php.test.bak');
237         }
238         else {
239             unlink('custom/modules/Emails/metadata/qcmodulesdefs.php');
240         }
241         
242         $this->assertEquals(array("Users"), $qArray);
243     }
244 }
245
246 class EmailUIMock extends EmailUI
247 {
248     public function _loadQuickCreateModules()
249     {
250         return parent::_loadQuickCreateModules();
251     }
252 }