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 Bug45573Test extends Sugar_PHPUnit_Framework_TestCase
40 var $hasCustomSearchFields;
42 public function setUp()
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']);
49 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
50 $GLOBALS['current_user']->is_admin = true;
52 if(file_exists('custom/modules/Cases/metadata/SearchFields.php'))
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');
60 public function tearDown()
62 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
64 if($this->hasCustomSearchFields && file_exists('custom/modules/Cases/metadata/SearchFields.php.bak'))
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');
72 //Refresh vardefs for Cases to reset
73 VardefManager::loadVardef('Cases', 'aCase', true);
77 * testActionAdvancedSearchViewSave
78 * This method tests to ensure that custom SearchFields are created or updated when a search layout change is made
80 public function testActionAdvancedSearchViewSave()
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'));
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']));
97 * testActionBasicSearchViewSave
98 * This method tests to ensure that custom SearchFields are created or updated when a search layout change is made
100 public function testActionBasicSearchViewSave()
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'));
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']));
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
121 public function testActionAdvancedSearchSaveWithoutAnyRangeSearchFields()
123 //Load the vardefs for the module to pass to TemplateRange
124 VardefManager::loadVardef('Cases', 'aCase', true);
126 $vardefs = $dictionary['Case']['fields'];
127 foreach($vardefs as $key=>$def)
129 if(!empty($def['enable_range_search']))
131 unset($vardefs[$key]['enable_range_search']);
135 require_once('modules/DynamicFields/templates/Fields/TemplateRange.php');
136 TemplateRange::repairCustomSearchFields($vardefs, 'Cases');
138 //In this case there would be no custom SearchFields.php file created
139 $this->assertTrue(!file_exists('custom/modules/Cases/metadata/SearchFields.php'));
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']));