]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Home/Bug44030Test.php
Release 6.2.0
[Github/sugarcrm.git] / tests / modules / Home / Bug44030Test.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 class Bug44030Test extends Sugar_PHPUnit_Framework_TestCase
39 {
40         var $unified_search_modules_file;
41     
42     public function setUp() 
43     {
44             global $beanList, $beanFiles, $dictionary;
45                 
46             //Add entries to simulate custom module
47             $beanList['Bug44030_TestPerson'] = 'Bug44030_TestPerson';
48             $beanFiles['Bug44030_TestPerson'] = 'modules/Bug44030_TestPerson/Bug44030_TestPerson.php';
49             
50             VardefManager::loadVardef('Contacts', 'Contact');
51             $dictionary['Bug44030_TestPerson'] = $dictionary['Contact'];
52             
53             //Copy over custom SearchFields.php file
54         if(!file_exists('custom/modules/Bug44030_TestPerson/metadata')) {
55                 mkdir_recursive('custom/modules/Bug44030_TestPerson/metadata');
56         }
57     
58     if( $fh = @fopen('custom/modules/Bug44030_TestPerson/metadata/SearchFields.php', 'w+') )
59     {
60 $string = <<<EOQ
61 <?php
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',
68 );
69 ?>
70 EOQ;
71        fputs( $fh, $string);
72        fclose( $fh );
73     }       
74             
75             
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))
79                 {
80                         copy($this->unified_search_modules_file, $this->unified_search_modules_file.'.bak');
81                         unlink($this->unified_search_modules_file);
82                 }               
83     }
84     
85     public function tearDown() 
86     {
87             global $beanList, $beanFiles, $dictionary;
88             
89                 if(file_exists($this->unified_search_modules_file . '.bak'))
90                 {
91                         copy($this->unified_search_modules_file . '.bak', $this->unified_search_modules_file);
92                         unlink($this->unified_search_modules_file . '.bak');
93                 }       
94                 
95                 if(file_exists('custom/modules/Bug44030_TestPerson/metadata/SearchFields.php'))
96                 {
97                         unlink('custom/modules/Bug44030_TestPerson/metadata/SearchFields.php');
98                         rmdir_recursive('custom/modules/Bug44030_TestPerson');
99                 }
100                 unset($beanFiles['Bug44030_TestPerson']);
101                 unset($beanList['Bug44030_TestPerson']);
102                 unset($dictionary['Bug44030_TestPerson']);
103     }
104         
105         public function testUnifiedSearchAdvancedBuildCache()
106         {
107                 require_once('modules/Home/UnifiedSearchAdvanced.php');
108                 $usa = new UnifiedSearchAdvanced();
109                 $usa->buildCache();
110                 
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");
113         
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");
117         }
118
119 }
120
121 ?>