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 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
55 $contact = new Contact();
56 $contact->id = 'l_'.$unid;
57 $contact->first_name = 'Greg';
58 $contact->last_name = 'Brady';
59 $contact->new_with_id = true;
61 $this->_contact = $contact;
63 if(file_exists(sugar_cached('modules/unified_search_modules.php')))
65 $this->_hasUnifiedSearchModulesConfig = true;
66 copy(sugar_cached('modules/unified_search_modules.php'), sugar_cached('modules/unified_search_modules.php.bak'));
67 unlink(sugar_cached('modules/unified_search_modules.php'));
70 if(file_exists('custom/modules/unified_search_modules_display.php'))
72 $this->_hasUnifiedSearchModulesDisplay = true;
73 copy('custom/modules/unified_search_modules_display.php', 'custom/modules/unified_search_modules_display.php.bak');
74 unlink('custom/modules/unified_search_modules_display.php');
80 public function tearDown()
82 $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$this->_contact->id}'");
83 unset($this->_contact);
85 if($this->_hasUnifiedSearchModulesConfig)
87 copy(sugar_cached('modules/unified_search_modules.php.bak'), sugar_cached('modules/unified_search_modules.php'));
88 unlink(sugar_cached('modules/unified_search_modules.php.bak'));
90 unlink(sugar_cached('modules/unified_search_modules.php'));
93 if($this->_hasUnifiedSearchModulesDisplay)
95 copy('custom/modules/unified_search_modules_display.php.bak', 'custom/modules/unified_search_modules_display.php');
96 unlink('custom/modules/unified_search_modules_display.php.bak');
98 unlink('custom/modules/unified_search_modules_display.php');
101 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
103 if(isset($_REQUEST['module']))
105 unset($_REQUEST['module']);
108 if(isset($_REQUEST['query_string']))
110 unset($_REQUEST['query_string']);
113 if(isset($_REQUEST['enabled_modules']))
115 unset($_REQUEST['enabled_modules']);
119 public function testSearchByFirstName()
121 global $mod_strings, $modListHeader, $app_strings, $beanList, $beanFiles;
122 require('config.php');
123 require('include/modules.php');
124 $modListHeader = $moduleList;
125 $_REQUEST['query_string'] = $this->_contact->first_name;
126 $_REQUEST['module'] = 'Home';
127 $usa = new UnifiedSearchAdvanced();
129 $this->expectOutputRegex("/{$this->_contact->first_name}/");
132 public function testSearchByFirstAndLastName()
134 global $mod_strings, $modListHeader, $app_strings, $beanList, $beanFiles;
135 require('config.php');
136 require('include/modules.php');
137 $_REQUEST['query_string'] = $this->_contact->first_name.' '.$this->_contact->last_name;
138 $_REQUEST['module'] = 'Home';
139 $usa = new UnifiedSearchAdvanced();
141 $this->expectOutputRegex("/{$this->_contact->first_name}/");
144 public function testUserPreferencesSearch()
146 global $mod_strings, $modListHeader, $app_strings, $beanList, $beanFiles, $current_user;
147 require('config.php');
148 require('include/modules.php');
150 $usa = new UnifiedSearchAdvanced();
151 $_REQUEST['enabled_modules'] = 'Accounts,Contacts';
152 $usa->saveGlobalSearchSettings();
155 $current_user->setPreference('globalSearch', array('Accounts', 'Contacts'), 0, 'search');
156 $current_user->savePreferencesToDB();
159 $_REQUEST['query_string'] = $this->_contact->first_name.' '.$this->_contact->last_name;
160 $_REQUEST['module'] = 'Home';
163 $modules = $current_user->getPreference('globalSearch', 'search');
164 $this->assertEquals(count($modules), 2, 'Assert that there are two modules in the user preferences as defined from the global search');
166 $this->assertEquals('Accounts', $modules[0], 'Assert that the Accounts module has been added');
167 $this->assertEquals('Contacts', $modules[1], 'Assert that the Contacts module has been added');