]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/UpgradeWizard/Bug37214Test.php
Release 6.2.0
[Github/sugarcrm.git] / tests / modules / UpgradeWizard / Bug37214Test.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 require_once('install/install_utils.php');
39 require_once('modules/UpgradeWizard/uw_utils.php');
40
41 class Bug37214Test extends Sugar_PHPUnit_Framework_TestCase {
42
43 var $original_argv;
44 var $has_original_config_si_file;
45 var $current_working_dir;
46
47 public function setUp() {
48         global $argv;
49         if(isset($argv))
50         {
51                 $this->original_argv = $argv;
52         }
53         
54                 
55         $this->current_working_dir = getcwd();
56         
57         if(file_exists('config.php'))
58         {
59            copy('config.php', 'config.php.bug37214');
60         }       
61         
62         if(file_exists($this->current_working_dir . DIRECTORY_SEPARATOR . 'config_si.php'))
63         {
64            $this->has_original_config_si_file = true;
65            copy($this->current_working_dir . DIRECTORY_SEPARATOR . 'config_si.php', $this->current_working_dir . DIRECTORY_SEPARATOR . 'config_si.php.bug37214');
66         } else {
67            $this->has_original_config_si_file = false;
68            copy('config.php', $this->current_working_dir . DIRECTORY_SEPARATOR . 'config_si.php');              
69         }
70         
71         $sugar_config_si = array(       
72                 'disable_count_query' => true,
73                 'external_cache_disabled_apc' => true,
74                 'external_cache_disabled_zend' => true,
75                 'external_cache_disabled_memcache' => true,
76                 'external_cache_disabled' => true,
77         );
78         
79         write_array_to_file("sugar_config_si", $sugar_config_si, $this->current_working_dir . DIRECTORY_SEPARATOR . 'config_si.php');
80 }
81
82 public function tearDown() {
83         if(isset($this->original_argv))
84         {
85                 global $argv;
86                 $argv = $this->original_argv;
87         }
88         
89         if(file_exists('config.php.bug37214'))
90         {
91            copy('config.php.bug37214', 'config.php');
92            unlink('config.php.bug37214');
93         }               
94         
95         if(file_exists($this->current_working_dir . DIRECTORY_SEPARATOR . 'config_si.php.bug37214'))
96         {
97            if($this->has_original_config_si_file) 
98            {
99                   copy($this->current_working_dir . DIRECTORY_SEPARATOR . 'config_si.php.bug37214', $this->current_working_dir . DIRECTORY_SEPARATOR . 'config_si.php');
100            } else {
101                   unlink($this->current_working_dir . DIRECTORY_SEPARATOR . 'config_si.php');
102            }
103            unlink($this->current_working_dir . DIRECTORY_SEPARATOR . 'config_si.php.bug37214');
104         }
105         else {
106             unlink($this->current_working_dir . DIRECTORY_SEPARATOR . 'config_si.php');
107         }
108 }
109         
110
111 public function test_silent_upgrade_parameters() {
112         if(!file_exists('config.php'))
113         {
114                 $this->markTestSkipped('Unable to locate config.php file.  Skipping test.');
115                 return;
116         }
117
118         
119         if(!file_exists($this->current_working_dir . DIRECTORY_SEPARATOR . 'config_si.php'))
120         {
121                 $this->markTestSkipped('Unable to locate config_si.php file.  Skipping test.');
122                 return;
123         }       
124
125         //Simulate silent upgrade arguments
126         global $argv;
127         $argv[0] = $this->current_working_dir . DIRECTORY_SEPARATOR . 'config.php'; //This would really be silentUpgrade.php, but this will suffice
128         $argv[1] = $this->current_working_dir . DIRECTORY_SEPARATOR . 'someZipFile.php';
129         $argv[2] = $this->current_working_dir . DIRECTORY_SEPARATOR . 'silent_upgrade.log';
130         $argv[3] = $this->current_working_dir;
131         $argv[4] = 'admin';
132         
133         $merge_result = merge_config_si_settings();
134         
135         include('config.php');
136         //echo var_export($sugar_config, true);
137         $this->assertEquals(true, $sugar_config['disable_count_query'], "Assert disable_count_query is set to true.");
138         $this->assertEquals(true, $sugar_config['external_cache_disabled_apc'], "Assert external_cache_disabled_apc is set to true.");
139         $this->assertEquals(true, $sugar_config['external_cache_disabled_zend'], "Assert external_cache_disabled_zend is set to true.");
140         $this->assertEquals(true, $sugar_config['external_cache_disabled_memcache'], "Assert external_cache_disabled_memcache is set to true.");
141         $this->assertEquals(true, $sugar_config['external_cache_disabled'], "Assert external_cache_disabled is set to true.");
142 }
143
144
145 /**
146  * test_silent_upgrade_parameters2
147  * This is similar to test_silent_upgrade_parameters except that $argv[0] simulates the current directory
148  * (imagine the caes of something like >php silentUpgrade.php xxx yyy zzz).  This is to prove that the
149  * merge_config_si_settings() can correctly determine the presence of the config_si.php file given the
150  * current directory.
151  * 
152  */
153 public function test_silent_upgrade_parameters2() {
154         
155         if(!file_exists('config.php'))
156         {
157                 $this->markTestSkipped('Unable to locate config.php file.  Skipping test.');
158                 return;
159         }
160
161         
162         if(!file_exists($this->current_working_dir . DIRECTORY_SEPARATOR . 'config_si.php'))
163         {
164                 $this->markTestSkipped('Unable to locate config_si.php file.  Skipping test.');
165                 return;
166         }       
167
168         //Simulate silent upgrade arguments
169         global $argv;
170         $argv[0] = 'config.php'; //This would really be silentUpgrade.php, but this will suffice
171         $argv[1] = $this->current_working_dir . DIRECTORY_SEPARATOR . 'someZipFile.php';
172         $argv[2] = $this->current_working_dir . DIRECTORY_SEPARATOR . 'silent_upgrade.log';
173         $argv[3] = $this->current_working_dir;
174         $argv[4] = 'admin';
175         
176         $merge_result = merge_config_si_settings(false);
177         //$this->assertEquals(true, $merge_result, "Assert that we have merged values");
178         
179         include('config.php');
180         //echo var_export($sugar_config, true);
181         $this->assertEquals(true, $sugar_config['disable_count_query'], "Assert disable_count_query is set to true.");
182         $this->assertEquals(true, $sugar_config['external_cache_disabled_apc'], "Assert external_cache_disabled_apc is set to true.");
183         $this->assertEquals(true, $sugar_config['external_cache_disabled_zend'], "Assert external_cache_disabled_zend is set to true.");
184         $this->assertEquals(true, $sugar_config['external_cache_disabled_memcache'], "Assert external_cache_disabled_memcache is set to true.");
185         $this->assertEquals(true, $sugar_config['external_cache_disabled'], "Assert external_cache_disabled is set to true.");
186 }
187
188
189 }
190
191 ?>