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 class Bug44030Test extends Sugar_PHPUnit_Framework_TestCase
40 var $unified_search_modules_file;
42 public function setUp()
44 global $beanList, $beanFiles, $dictionary;
46 //Add entries to simulate custom module
47 $beanList['Bug44030_TestPerson'] = 'Bug44030_TestPerson';
48 $beanFiles['Bug44030_TestPerson'] = 'modules/Bug44030_TestPerson/Bug44030_TestPerson.php';
50 VardefManager::loadVardef('Contacts', 'Contact');
51 $dictionary['Bug44030_TestPerson'] = $dictionary['Contact'];
53 //Copy over custom SearchFields.php file
54 if(!file_exists('custom/modules/Bug44030_TestPerson/metadata')) {
55 mkdir_recursive('custom/modules/Bug44030_TestPerson/metadata');
58 if( $fh = @fopen('custom/modules/Bug44030_TestPerson/metadata/SearchFields.php', 'w+') )
62 \$searchFields['Bug44030_TestPerson']['email'] = array(
63 'query_type' => 'default',
64 'operator' => 'subquery',
65 'subquery' => 'SELECT eabr.bean_id FROM email_addr_bean_rel eabr JOIN email_addresses ea ON (ea.id = eabr.email_address_id) WHERE eabr.deleted=0 AND ea.email_address LIKE',
66 'db_field' => array('id',),
67 'vname' =>'LBL_ANY_EMAIL',
76 //Remove the cached unified_search_modules.php file
77 $this->unified_search_modules_file = $GLOBALS['sugar_config']['cache_dir'] . 'modules/unified_search_modules.php';
78 if(file_exists($this->unified_search_modules_file))
80 copy($this->unified_search_modules_file, $this->unified_search_modules_file.'.bak');
81 unlink($this->unified_search_modules_file);
85 public function tearDown()
87 global $beanList, $beanFiles, $dictionary;
89 if(file_exists($this->unified_search_modules_file . '.bak'))
91 copy($this->unified_search_modules_file . '.bak', $this->unified_search_modules_file);
92 unlink($this->unified_search_modules_file . '.bak');
95 if(file_exists('custom/modules/Bug44030_TestPerson/metadata/SearchFields.php'))
97 unlink('custom/modules/Bug44030_TestPerson/metadata/SearchFields.php');
98 rmdir_recursive('custom/modules/Bug44030_TestPerson');
100 unset($beanFiles['Bug44030_TestPerson']);
101 unset($beanList['Bug44030_TestPerson']);
102 unset($dictionary['Bug44030_TestPerson']);
105 public function testUnifiedSearchAdvancedBuildCache()
107 require_once('modules/Home/UnifiedSearchAdvanced.php');
108 $usa = new UnifiedSearchAdvanced();
111 //Assert we could build the file without problems
112 $this->assertTrue(file_exists($this->unified_search_modules_file), "Assert {$this->unified_search_modules_file} file was created");
114 include($this->unified_search_modules_file);
115 $this->assertTrue(isset($unified_search_modules['Bug44030_TestPerson']), "Assert that we have the custom module set in unified_search_modules.php file");
116 $this->assertTrue(isset($unified_search_modules['Bug44030_TestPerson']['fields']['email']), "Assert that the email field was set for the custom module");