]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Home/UnifiedSearchAdvancedTest.php
Release 6.5.16
[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-2013 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         SugarTestHelper::setUp('beanList');
54         SugarTestHelper::setUp('beanFiles');
55         SugarTestHelper::setUp('app_strings');
56         SugarTestHelper::setUp('app_list_strings');
57         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
58         $unid = uniqid();
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;
64         $contact->save();
65         $this->_contact = $contact;
66
67         if(file_exists(sugar_cached('modules/unified_search_modules.php')))
68         {
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'));
72         }
73
74         if(file_exists('custom/modules/unified_search_modules_display.php'))
75         {
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');
79         }
80
81         
82         }
83
84         public function tearDown()
85         {
86         SugarTestHelper::tearDown();
87
88         $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$this->_contact->id}'");
89         unset($this->_contact);
90
91         if($this->_hasUnifiedSearchModulesConfig)
92         {
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'));
95         } else {
96                 unlink(sugar_cached('modules/unified_search_modules.php'));
97         }
98
99         if($this->_hasUnifiedSearchModulesDisplay)
100         {
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');
103         } else {
104                 unlink('custom/modules/unified_search_modules_display.php');
105         }
106
107         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
108
109         if(isset($_REQUEST['module']))
110         {
111             unset($_REQUEST['module']);
112         }
113
114         if(isset($_REQUEST['query_string']))
115         {
116             unset($_REQUEST['query_string']);
117         }
118
119         if(isset($_REQUEST['enabled_modules']))
120         {
121             unset($_REQUEST['enabled_modules']);
122         }
123         }
124
125         public function testSearchByFirstName()
126         {
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();
134                 $usa->search();
135                 $this->expectOutputRegex("/{$this->_contact->first_name}/");
136     }
137
138         public function testSearchByFirstAndLastName()
139         {
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();
146                 $usa->search();
147                 $this->expectOutputRegex("/{$this->_contact->first_name}/");
148     }
149
150     public function testUserPreferencesSearch()
151     {
152                 global $mod_strings, $modListHeader, $app_strings, $beanList, $beanFiles, $current_user;
153                 require('config.php');
154                 require('include/modules.php');
155
156         $usa = new UnifiedSearchAdvanced();
157         $_REQUEST['enabled_modules'] = 'Accounts,Contacts';
158         $usa->saveGlobalSearchSettings();
159
160
161         $current_user->setPreference('globalSearch', array('Accounts', 'Contacts'), 0, 'search');
162         $current_user->savePreferencesToDB();
163         
164         $_REQUEST = array();
165                 $_REQUEST['query_string'] = $this->_contact->first_name.' '.$this->_contact->last_name;
166         $_REQUEST['module'] = 'Home';
167         $usa->search();
168
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');
171
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');
174     }
175 }
176