2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2013 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/Home/UnifiedSearchAdvanced.php';
39 require_once 'modules/Contacts/Contact.php';
40 require_once 'include/utils/layout_utils.php';
45 class UnifiedSearchAdvancedTest extends Sugar_PHPUnit_Framework_OutputTestCase
47 protected $_contact = null;
48 private $_hasUnifiedSearchModulesConfig = false;
49 private $_hasUnifiedSearchModulesDisplay = false;
51 public function setUp()
53 SugarTestHelper::setUp('beanList');
54 SugarTestHelper::setUp('beanFiles');
55 SugarTestHelper::setUp('app_strings');
56 SugarTestHelper::setUp('app_list_strings');
57 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
59 $contact = new Contact();
60 $contact->id = 'l_'.$unid;
61 $contact->first_name = 'Greg';
62 $contact->last_name = 'Brady';
63 $contact->new_with_id = true;
65 $this->_contact = $contact;
67 if(file_exists(sugar_cached('modules/unified_search_modules.php')))
69 $this->_hasUnifiedSearchModulesConfig = true;
70 copy(sugar_cached('modules/unified_search_modules.php'), sugar_cached('modules/unified_search_modules.php.bak'));
71 unlink(sugar_cached('modules/unified_search_modules.php'));
74 if(file_exists('custom/modules/unified_search_modules_display.php'))
76 $this->_hasUnifiedSearchModulesDisplay = true;
77 copy('custom/modules/unified_search_modules_display.php', 'custom/modules/unified_search_modules_display.php.bak');
78 unlink('custom/modules/unified_search_modules_display.php');
84 public function tearDown()
86 SugarTestHelper::tearDown();
88 $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$this->_contact->id}'");
89 unset($this->_contact);
91 if($this->_hasUnifiedSearchModulesConfig)
93 copy(sugar_cached('modules/unified_search_modules.php.bak'), sugar_cached('modules/unified_search_modules.php'));
94 unlink(sugar_cached('modules/unified_search_modules.php.bak'));
96 unlink(sugar_cached('modules/unified_search_modules.php'));
99 if($this->_hasUnifiedSearchModulesDisplay)
101 copy('custom/modules/unified_search_modules_display.php.bak', 'custom/modules/unified_search_modules_display.php');
102 unlink('custom/modules/unified_search_modules_display.php.bak');
104 unlink('custom/modules/unified_search_modules_display.php');
107 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
109 if(isset($_REQUEST['module']))
111 unset($_REQUEST['module']);
114 if(isset($_REQUEST['query_string']))
116 unset($_REQUEST['query_string']);
119 if(isset($_REQUEST['enabled_modules']))
121 unset($_REQUEST['enabled_modules']);
125 public function testSearchByFirstName()
127 global $mod_strings, $modListHeader, $app_strings, $beanList, $beanFiles;
128 require('config.php');
129 require('include/modules.php');
130 $modListHeader = $moduleList;
131 $_REQUEST['query_string'] = $this->_contact->first_name;
132 $_REQUEST['module'] = 'Home';
133 $usa = new UnifiedSearchAdvanced();
135 $this->expectOutputRegex("/{$this->_contact->first_name}/");
138 public function testSearchByFirstAndLastName()
140 global $mod_strings, $modListHeader, $app_strings, $beanList, $beanFiles;
141 require('config.php');
142 require('include/modules.php');
143 $_REQUEST['query_string'] = $this->_contact->first_name.' '.$this->_contact->last_name;
144 $_REQUEST['module'] = 'Home';
145 $usa = new UnifiedSearchAdvanced();
147 $this->expectOutputRegex("/{$this->_contact->first_name}/");
150 public function testUserPreferencesSearch()
152 global $mod_strings, $modListHeader, $app_strings, $beanList, $beanFiles, $current_user;
153 require('config.php');
154 require('include/modules.php');
156 $usa = new UnifiedSearchAdvanced();
157 $_REQUEST['enabled_modules'] = 'Accounts,Contacts';
158 $usa->saveGlobalSearchSettings();
161 $current_user->setPreference('globalSearch', array('Accounts', 'Contacts'), 0, 'search');
162 $current_user->savePreferencesToDB();
165 $_REQUEST['query_string'] = $this->_contact->first_name.' '.$this->_contact->last_name;
166 $_REQUEST['module'] = 'Home';
169 $modules = $current_user->getPreference('globalSearch', 'search');
170 $this->assertEquals(count($modules), 2, 'Assert that there are two modules in the user preferences as defined from the global search');
172 $this->assertEquals('Accounts', $modules[0], 'Assert that the Accounts module has been added');
173 $this->assertEquals('Contacts', $modules[1], 'Assert that the Contacts module has been added');