]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/ModuleBuilder/Bug45573Test.php
Release 6.2.2
[Github/sugarcrm.git] / tests / modules / ModuleBuilder / Bug45573Test.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 Bug45573Test extends Sugar_PHPUnit_Framework_TestCase
39 {
40         var $hasCustomSearchFields;
41         
42         public function setUp()
43         {
44             require('include/modules.php');
45             $GLOBALS['beanList'] = $beanList;
46             $GLOBALS['beanFiles'] = $beanFiles;
47             $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
48             
49             $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
50             $GLOBALS['current_user']->is_admin = true;
51                 
52                 if(file_exists('custom/modules/Cases/metadata/SearchFields.php'))
53                 {                       
54                         $this->hasCustomSearchFields = true;
55             copy('custom/modules/Cases/metadata/SearchFields.php', 'custom/modules/Cases/metadata/SearchFields.php.bak');
56             unlink('custom/modules/Cases/metadata/SearchFields.php');                   
57                 }
58         }
59         
60         public function tearDown()
61         {
62                 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
63                 
64                 if($this->hasCustomSearchFields && file_exists('custom/modules/Cases/metadata/SearchFields.php.bak'))
65                 {
66                    copy('custom/modules/Cases/metadata/SearchFields.php.bak', 'custom/modules/Cases/metadata/SearchFields.php');
67                    unlink('custom/modules/Cases/metadata/SearchFields.php.bak');
68                 } else if(!$this->hasCustomSearchFields && file_exists('custom/modules/Cases/metadata/SearchFields.php')) {
69                    unlink('custom/modules/Cases/metadata/SearchFields.php');
70                 }
71                 
72                 //Refresh vardefs for Cases to reset
73                 VardefManager::loadVardef('Cases', 'aCase', true); 
74         }
75         
76         /**
77          * testActionAdvancedSearchViewSave
78          * This method tests to ensure that custom SearchFields are created or updated when a search layout change is made
79          */
80         public function testActionAdvancedSearchViewSave()
81         {
82                 require_once('modules/ModuleBuilder/controller.php');
83                 $mbController = new ModuleBuilderController();
84                 $_REQUEST['view_module'] = 'Cases';
85                 $_REQUEST['view'] = 'advanced_search';
86                 $mbController->action_searchViewSave();
87                 $this->assertTrue(file_exists('custom/modules/Cases/metadata/SearchFields.php'));
88                 
89                 require('custom/modules/Cases/metadata/SearchFields.php');
90                 $this->assertTrue(isset($searchFields['Cases']['range_date_entered']));
91                 $this->assertTrue(isset($searchFields['Cases']['range_date_entered']['enable_range_search']));
92                 $this->assertTrue(isset($searchFields['Cases']['range_date_modified']));
93                 $this->assertTrue(isset($searchFields['Cases']['range_date_modified']['enable_range_search']));
94         }
95         
96         /**
97          * testActionBasicSearchViewSave
98          * This method tests to ensure that custom SearchFields are created or updated when a search layout change is made
99          */
100         public function testActionBasicSearchViewSave()
101         {
102                 require_once('modules/ModuleBuilder/controller.php');
103                 $mbController = new ModuleBuilderController();
104                 $_REQUEST['view_module'] = 'Cases';
105                 $_REQUEST['view'] = 'basic_search';
106                 $mbController->action_searchViewSave();
107                 $this->assertTrue(file_exists('custom/modules/Cases/metadata/SearchFields.php'));
108                 
109                 require('custom/modules/Cases/metadata/SearchFields.php');
110                 $this->assertTrue(isset($searchFields['Cases']['range_date_entered']));
111                 $this->assertTrue(isset($searchFields['Cases']['range_date_entered']['enable_range_search']));
112                 $this->assertTrue(isset($searchFields['Cases']['range_date_modified']));
113                 $this->assertTrue(isset($searchFields['Cases']['range_date_modified']['enable_range_search']));
114         }       
115         
116         
117         /**
118          * testActionAdvancedSearchSaveWithoutAnyRangeSearchFields
119          * One last test to check what would happen if we had a module that did not have any range search fields enabled
120          */
121         public function testActionAdvancedSearchSaveWithoutAnyRangeSearchFields()
122         {
123         //Load the vardefs for the module to pass to TemplateRange
124         VardefManager::loadVardef('Cases', 'aCase', true); 
125         global $dictionary;      
126         $vardefs = $dictionary['Case']['fields'];
127         foreach($vardefs as $key=>$def)
128         {
129                 if(!empty($def['enable_range_search']))
130                 {
131                         unset($vardefs[$key]['enable_range_search']);
132                 }
133         }
134         
135         require_once('modules/DynamicFields/templates/Fields/TemplateRange.php');
136         TemplateRange::repairCustomSearchFields($vardefs, 'Cases');     
137                 
138         //In this case there would be no custom SearchFields.php file created
139                 $this->assertTrue(!file_exists('custom/modules/Cases/metadata/SearchFields.php'));
140                 
141                 //Yet we have the defaults set still in out of box settings
142                 require('modules/Cases/metadata/SearchFields.php');
143                 $this->assertTrue(isset($searchFields['Cases']['range_date_entered']));
144                 $this->assertTrue(isset($searchFields['Cases']['range_date_entered']['enable_range_search']));
145                 $this->assertTrue(isset($searchFields['Cases']['range_date_modified']));
146                 $this->assertTrue(isset($searchFields['Cases']['range_date_modified']['enable_range_search']));
147         }
148                 
149 }
150
151 ?>