2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
38 require_once('modules/Emails/EmailUI.php');
40 class EmailUITest extends Sugar_PHPUnit_Framework_TestCase
42 private $_folders = null;
44 public function setUp()
47 $this->_user = SugarTestUserUtilities::createAnonymousUser();
48 $this->_user->is_admin = 1;
49 $GLOBALS['current_user'] = $this->_user;
50 $this->eui = new EmailUIMock();
52 $this->_folders = array();
56 require('include/modules.php');
57 $GLOBALS['beanList'] = $beanList;
58 $GLOBALS['beanFiles'] = $beanFiles;
61 public function tearDown()
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}'");
69 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
70 unset($GLOBALS['current_user']);
72 unset($GLOBALS['beanList']);
73 unset($GLOBALS['beanFiles']);
74 $GLOBALS['db']->query("DELETE FROM folders_subscriptions WHERE assigned_user_id='{$this->_user->id}'");
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}'");
85 public function testSaveNewFolder()
87 $newFolderName = "UNIT_TEST";
88 $rs = $this->eui->saveNewFolder($newFolderName,'Home',0);
89 $newFolderID = $rs['id'];
90 $this->_folders[] = $newFolderID;
92 $sf = new SugarFolder();
93 $sf->retrieve($newFolderID);
94 $this->assertEquals($newFolderName, $sf->name);
99 * Save the user preference for list view order per IE account.
102 public function testSaveListViewSortOrder()
104 $tmpId = create_guid();
105 $folderName = "UNIT_TEST";
106 $sortBy = 'last_name';
108 $rs = $this->eui->saveListViewSortOrder($tmpId,$folderName,$sortBy,$dir);
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']);
117 public function testGetRelatedEmail()
120 $account = new Account();
121 $account->name = "emailTestAccount";
122 $account->save(false);
124 $relatedBeanInfo = array('related_bean_id' => $account->id, "related_bean_type" => "Accounts");
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']);
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);
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);
142 $a = $account->db->fetchByAssoc($r);
143 $person['bean_id'] = $a['id'];
144 $person['bean_module'] = $a['module'];
145 $person['email'] = $a['email_address'];
148 $GLOBALS['db']->query("DELETE FROM accounts WHERE id= '{$account->id}'");
149 $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$contact->id}'");
151 $this->assertEquals("test@test.com", $person['email']);
157 public function testLoadQuickCreateModules()
159 $qArray = $this->eui->_loadQuickCreateModules();
161 $this->assertEquals(array('Bugs','Cases','Contacts', 'Leads', 'Tasks'), $qArray);
167 public function testLoadCustomQuickCreateModulesCanMergeModules()
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');
172 sugar_mkdir("custom/modules/Emails/metadata/",null,true);
174 'custom/modules/Emails/metadata/qcmodulesdefs.php',
175 '<?php $QCModules[] = "Users"; ?>'
178 $qArray = $this->eui->_loadQuickCreateModules();
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');
185 unlink('custom/modules/Emails/metadata/qcmodulesdefs.php');
188 $this->assertEquals(array('Bugs','Cases','Contacts', 'Leads', 'Tasks', 'Users'), $qArray);
194 public function testLoadQuickCreateModulesInvalidModule()
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');
199 sugar_mkdir("custom/modules/Emails/metadata/",null,true);
201 'custom/modules/Emails/metadata/qcmodulesdefs.php',
202 '<?php $QCModules[] = "EmailUIUnitTest"; ?>'
205 $qArray = $this->eui->_loadQuickCreateModules();
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');
212 unlink('custom/modules/Emails/metadata/qcmodulesdefs.php');
215 $this->assertEquals(array('Bugs','Cases','Contacts', 'Leads', 'Tasks'), $qArray);
221 public function testLoadQuickCreateModulesCanOverrideDefaultModules()
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');
226 sugar_mkdir("custom/modules/Emails/metadata/",null,true);
228 'custom/modules/Emails/metadata/qcmodulesdefs.php',
229 '<?php $QCModules = array("Users"); ?>'
232 $qArray = $this->eui->_loadQuickCreateModules();
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');
239 unlink('custom/modules/Emails/metadata/qcmodulesdefs.php');
242 $this->assertEquals(array("Users"), $qArray);
246 class EmailUIMock extends EmailUI
248 public function _loadQuickCreateModules()
250 return parent::_loadQuickCreateModules();