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/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('cache/modules/unified_search_modules.php'))
65 $this->_hasUnifiedSearchModulesConfig = true;
66 copy('cache/modules/unified_search_modules.php', 'cache/modules/unified_search_modules.php.bak');
67 unlink('cache/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');
79 public function tearDown()
81 $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$this->_contact->id}'");
82 unset($this->_contact);
84 if($this->_hasUnifiedSearchModulesConfig)
86 copy('cache/modules/unified_search_modules.php.bak', 'cache/modules/unified_search_modules.php');
87 unlink('cache/modules/unified_search_modules.php.bak');
89 unlink('cache/modules/unified_search_modules.php');
92 if($this->_hasUnifiedSearchModulesDisplay)
94 copy('custom/modules/unified_search_modules_display.php.bak', 'custom/modules/unified_search_modules_display.php');
95 unlink('custom/modules/unified_search_modules_display.php.bak');
97 unlink('custom/modules/unified_search_modules_display.php');
101 public function testSearchByFirstName()
103 global $mod_strings, $modListHeader, $app_strings, $beanList, $beanFiles;
104 require('config.php');
105 require('include/modules.php');
106 $modListHeader = $moduleList;
107 $_REQUEST['query_string'] = $this->_contact->first_name;
108 $_REQUEST['module'] = 'Home';
109 $usa = new UnifiedSearchAdvanced();
111 $this->expectOutputRegex("/{$this->_contact->first_name}/");
114 public function testSearchByFirstAndLastName()
116 global $mod_strings, $modListHeader, $app_strings, $beanList, $beanFiles;
117 require('config.php');
118 require('include/modules.php');
119 $_REQUEST['query_string'] = $this->_contact->first_name.' '.$this->_contact->last_name;
120 $_REQUEST['module'] = 'Home';
121 $usa = new UnifiedSearchAdvanced();
123 $this->expectOutputRegex("/{$this->_contact->first_name}/");
126 public function testUserPreferencesSearch()
128 global $mod_strings, $modListHeader, $app_strings, $beanList, $beanFiles;
129 require('config.php');
130 require('include/modules.php');
132 $usa = new UnifiedSearchAdvanced();
133 $_REQUEST['enabled_modules'] = 'Accounts,Contacts';
134 $usa->saveGlobalSearchSettings();
137 $_REQUEST['query_string'] = $this->_contact->first_name.' '.$this->_contact->last_name;
138 $_REQUEST['module'] = 'Home';
140 global $current_user;
141 $modules = $current_user->getPreference('globalSearch', 'search');
142 $this->assertEquals(count($modules), 2, 'Assert that there are two modules in the user preferences as defined from the global search');
143 $this->assertTrue(isset($modules['Accounts']) && isset($modules['Contacts']), 'Assert that the Accounts and Contacts modules have been added');