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 $GLOBALS['current_user'] = $this->_user;
49 $this->eui = new EmailUIMock();
51 $this->_folders = array();
55 require('include/modules.php');
56 $GLOBALS['beanList'] = $beanList;
57 $GLOBALS['beanFiles'] = $beanFiles;
60 public function tearDown()
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}'");
68 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
69 unset($GLOBALS['current_user']);
71 unset($GLOBALS['beanList']);
72 unset($GLOBALS['beanFiles']);
73 $GLOBALS['db']->query("DELETE FROM folders_subscriptions WHERE assigned_user_id='{$this->_user->id}'");
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}'");
84 public function testSaveNewFolder()
86 $newFolderName = "UNIT_TEST";
87 $rs = $this->eui->saveNewFolder($newFolderName,'Home',0);
88 $newFolderID = $rs['id'];
89 $this->_folders[] = $newFolderID;
91 $sf = new SugarFolder();
92 $sf->retrieve($newFolderID);
93 $this->assertEquals($newFolderName, $sf->name);
98 * Save the user preference for list view order per IE account.
101 public function testSaveListViewSortOrder()
103 $tmpId = create_guid();
104 $folderName = "UNIT_TEST";
105 $sortBy = 'last_name';
107 $rs = $this->eui->saveListViewSortOrder($tmpId,$folderName,$sortBy,$dir);
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']);
116 public function testGetRelatedEmail()
119 $account = new Account();
120 $account->name = "emailTestAccount";
121 $account->save(false);
123 $relatedBeanInfo = array('related_bean_id' => $account->id, "related_bean_type" => "Accounts");
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']);
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);
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);
141 $a = $account->db->fetchByAssoc($r);
142 $person['bean_id'] = $a['id'];
143 $person['bean_module'] = $a['module'];
144 $person['email'] = $a['email_address'];
147 $GLOBALS['db']->query("DELETE FROM accounts WHERE id= '{$account->id}'");
148 $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$contact->id}'");
150 $this->assertEquals("test@test.com", $person['email']);
156 public function testLoadQuickCreateModules()
158 $qArray = $this->eui->_loadQuickCreateModules();
160 $this->assertEquals(array('Bugs','Cases','Contacts', 'Leads', 'Tasks'), $qArray);
166 public function testLoadCustomQuickCreateModulesCanMergeModules()
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');
171 sugar_mkdir("custom/modules/Emails/metadata/",null,true);
173 'custom/modules/Emails/metadata/qcmodulesdefs.php',
174 '<?php $QCModules[] = "Users"; ?>'
177 $qArray = $this->eui->_loadQuickCreateModules();
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');
184 unlink('custom/modules/Emails/metadata/qcmodulesdefs.php');
187 $this->assertEquals(array('Bugs','Cases','Contacts', 'Leads', 'Tasks', 'Users'), $qArray);
193 public function testLoadQuickCreateModulesInvalidModule()
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');
198 sugar_mkdir("custom/modules/Emails/metadata/",null,true);
200 'custom/modules/Emails/metadata/qcmodulesdefs.php',
201 '<?php $QCModules[] = "EmailUIUnitTest"; ?>'
204 $qArray = $this->eui->_loadQuickCreateModules();
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');
211 unlink('custom/modules/Emails/metadata/qcmodulesdefs.php');
214 $this->assertEquals(array('Bugs','Cases','Contacts', 'Leads', 'Tasks'), $qArray);
220 public function testLoadQuickCreateModulesCanOverrideDefaultModules()
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');
225 sugar_mkdir("custom/modules/Emails/metadata/",null,true);
227 'custom/modules/Emails/metadata/qcmodulesdefs.php',
228 '<?php $QCModules = array("Users"); ?>'
231 $qArray = $this->eui->_loadQuickCreateModules();
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');
238 unlink('custom/modules/Emails/metadata/qcmodulesdefs.php');
241 $this->assertEquals(array("Users"), $qArray);
245 class EmailUIMock extends EmailUI
247 public function _loadQuickCreateModules()
249 return parent::_loadQuickCreateModules();