]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Home/UnifiedSearchAdvancedTest.php
Release 6.4.0
[Github/sugarcrm.git] / tests / modules / Home / UnifiedSearchAdvancedTest.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
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.
12  * 
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
16  * details.
17  * 
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
21  * 02110-1301 USA.
22  * 
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.
25  * 
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.
29  * 
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  ********************************************************************************/
36
37  
38 require_once 'modules/Home/UnifiedSearchAdvanced.php';
39 require_once 'modules/Contacts/Contact.php';
40 require_once 'include/utils/layout_utils.php';
41
42 /**
43  * @ticket 34125
44  */
45 class UnifiedSearchAdvancedTest extends Sugar_PHPUnit_Framework_OutputTestCase
46 {
47     protected $_contact = null;
48     private $_hasUnifiedSearchModulesConfig = false;
49     private $_hasUnifiedSearchModulesDisplay = false;
50
51     public function setUp()
52     {
53         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
54         $unid = uniqid();
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;
60         $contact->save();
61         $this->_contact = $contact;
62
63         if(file_exists(sugar_cached('modules/unified_search_modules.php')))
64         {
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'));
68         }
69
70         if(file_exists('custom/modules/unified_search_modules_display.php'))
71         {
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');
75         }
76
77         
78         }
79
80         public function tearDown()
81         {
82         $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$this->_contact->id}'");
83         unset($this->_contact);
84
85         if($this->_hasUnifiedSearchModulesConfig)
86         {
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'));
89         } else {
90                 unlink(sugar_cached('modules/unified_search_modules.php'));
91         }
92
93         if($this->_hasUnifiedSearchModulesDisplay)
94         {
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');
97         } else {
98                 unlink('custom/modules/unified_search_modules_display.php');
99         }
100
101         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
102
103         if(isset($_REQUEST['module']))
104         {
105             unset($_REQUEST['module']);
106         }
107
108         if(isset($_REQUEST['query_string']))
109         {
110             unset($_REQUEST['query_string']);
111         }
112
113         if(isset($_REQUEST['enabled_modules']))
114         {
115             unset($_REQUEST['enabled_modules']);
116         }
117         }
118
119         public function testSearchByFirstName()
120         {
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();
128                 $usa->search();
129                 $this->expectOutputRegex("/{$this->_contact->first_name}/");
130     }
131
132         public function testSearchByFirstAndLastName()
133         {
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();
140                 $usa->search();
141                 $this->expectOutputRegex("/{$this->_contact->first_name}/");
142     }
143
144     public function testUserPreferencesSearch()
145     {
146                 global $mod_strings, $modListHeader, $app_strings, $beanList, $beanFiles, $current_user;
147                 require('config.php');
148                 require('include/modules.php');
149
150         $usa = new UnifiedSearchAdvanced();
151         $_REQUEST['enabled_modules'] = 'Accounts,Contacts';
152         $usa->saveGlobalSearchSettings();
153
154
155         $current_user->setPreference('globalSearch', array('Accounts', 'Contacts'), 0, 'search');
156         $current_user->savePreferencesToDB();
157         
158         $_REQUEST = array();
159                 $_REQUEST['query_string'] = $this->_contact->first_name.' '.$this->_contact->last_name;
160         $_REQUEST['module'] = 'Home';
161         $usa->search();
162
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');
165
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');
168     }
169 }
170