]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/ModuleInstall/Bug56228Test.php
Release 6.5.16
[Github/sugarcrm.git] / tests / ModuleInstall / Bug56228Test.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2013 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
39 require_once('ModuleInstall/ModuleInstaller.php');
40
41
42 class Bug56228Test extends Sugar_PHPUnit_Framework_TestCase
43 {
44     private $fileNames;
45
46     /**
47      * @group 56228
48      */
49     public function testUninstallNoFilesModStr()
50     {
51         $files = array(
52             'custom/Extension/modules/relationships/language/Bugs.php' => "<?php\n//THIS FILE IS AUTO GENERATED, DO NOT MODIFY\n"
53                 . "\$mod_strings['LBL_OPPORTUNITIES_BUGS_1_FROM_OPPORTUNITIES_TITLE'] = 'Opportunities';\n",
54             'custom/Extension/modules/relationships/language/Opportunities.php' => "<?php\n//THIS FILE IS AUTO GENERATED, DO NOT MODIFY\n"
55                 . "\$mod_strings['LBL_OPPORTUNITIES_BUGS_1_FROM_OPPORTUNITIES_TITLE'] = 'Opportunities';\n"
56                 . "\$mod_strings['LBL_OPPORTUNITIES_BUGS_1_FROM_BUGS_TITLE'] ='Bugs';",
57         );
58
59         $labelDefinitions = array(
60             array(
61                 'module' => 'Bugs',
62                 'system_label' => 'LBL_OPPORTUNITIES_BUGS_1_FROM_OPPORTUNITIES_TITLE',
63                 'display_label' => 'Opportunities',
64             ),
65             array(
66                 'module' => 'Opportunities',
67                 'system_label' => 'LBL_OPPORTUNITIES_BUGS_1_FROM_BUGS_TITLE',
68                 'display_label' => 'Bugs',
69             ),
70         );
71
72         $this->writeTestFiles($files);
73         $this->uninstallLabels($labelDefinitions);
74
75         $this->assertFileNotExists(
76             'custom/Extension/modules/relationships/language/Bugs.php',
77             'Not deleted empty file'
78         );
79         $this->assertFileNotExists(
80             'custom/Extension/modules/relationships/language/Opportunities.php',
81             'Not deleted empty file'
82         );
83
84     }
85
86     /**
87      * @group 56228
88      */
89     public function testUninstallWithFilesModStr()
90     {
91         $files = array(
92             'custom/Extension/modules/relationships/language/Bugs.php' => "<?php\n//THIS FILE IS AUTO GENERATED, DO NOT MODIFY\n"
93                 . "\$mod_strings['LBL_OPPORTUNITIES_BUGS_1_FROM_OPPORTUNITIES_TITLE'] = 'Opportunities';\n"
94                 . "\$mod_strings['LBL_OTHER_LABEL'] = 'Other label';\n",
95             'custom/Extension/modules/relationships/language/Opportunities.php' => "<?php\n//THIS FILE IS AUTO GENERATED, DO NOT MODIFY\n"
96                 . "\$mod_strings['LBL_OPPORTUNITIES_BUGS_1_FROM_OPPORTUNITIES_TITLE'] = 'Opportunities';\n"
97                 . "\$mod_strings['LBL_OPPORTUNITIES_BUGS_1_FROM_BUGS_TITLE'] ='Bugs';",
98         );
99
100         $labelDefinitions = array(
101             array(
102                 'module' => 'Bugs',
103                 'system_label' => 'LBL_OPPORTUNITIES_BUGS_1_FROM_OPPORTUNITIES_TITLE',
104                 'display_label' => 'Opportunities',
105             ),
106             array(
107                 'module' => 'Opportunities',
108                 'system_label' => 'LBL_OPPORTUNITIES_BUGS_1_FROM_BUGS_TITLE',
109                 'display_label' => 'Bugs',
110             ),
111         );
112
113         $this->writeTestFiles($files);
114         $this->uninstallLabels($labelDefinitions);
115
116
117         $this->assertFileNotExists('custom/Extension/modules/relationships/language/Opportunities.php');
118
119         $this->assertFileExists('custom/Extension/modules/relationships/language/Bugs.php');
120         require('custom/Extension/modules/relationships/language/Bugs.php');
121         $this->assertArrayNotHasKey('LBL_OPPORTUNITIES_BUGS_1_FROM_OPPORTUNITIES_TITLE', $mod_strings);
122         $this->assertArrayNotHasKey('LBL_OPPORTUNITIES_BUGS_1_FROM_BUGS_TITLE', $mod_strings);
123
124     }
125
126     /**
127      * @group 56228
128      */
129     public function testUninstallWithFilesAppStr()
130     {
131         $files = array(
132             'custom/Extension/modules/relationships/language/application.php' => "<?php\n//THIS FILE IS AUTO GENERATED, DO NOT MODIFY\n"
133                 . "\$app_list_strings['LBL_OTHER_LABEL'] = 'Other label';\n"
134                 . "\$app_list_strings['LBL_OPPORTUNITIES_BUGS_1_FROM_OPPORTUNITIES_TITLE'] = 'Opportunities';\n"
135                 . "\$app_list_strings['LBL_OPPORTUNITIES_BUGS_1_FROM_BUGS_TITLE'] ='Bugs';",
136         );
137
138         $labelDefinitions = array(
139             array(
140                 'module' => 'application',
141                 'system_label' => 'LBL_OPPORTUNITIES_BUGS_1_FROM_OPPORTUNITIES_TITLE',
142                 'display_label' => 'Opportunities',
143             ),
144
145             array(
146                 'module' => 'application',
147                 'system_label' => 'LBL_OPPORTUNITIES_BUGS_1_FROM_BUGS_TITLE',
148                 'display_label' => 'Bugs',
149             ),
150
151         );
152
153         $this->writeTestFiles($files);
154         $this->uninstallLabels($labelDefinitions);
155
156         $this->assertFileExists('custom/Extension/modules/relationships/language/application.php');
157         require('custom/Extension/modules/relationships/language/application.php');
158         $this->assertArrayNotHasKey('LBL_OPPORTUNITIES_BUGS_1_FROM_OPPORTUNITIES_TITLE', $app_list_strings);
159         $this->assertArrayNotHasKey('LBL_OPPORTUNITIES_BUGS_1_FROM_BUGS_TITLE', $app_list_strings);
160
161     }
162
163     /**
164      * @group 56228
165      */
166     public function testUninstallNoFilesAppStr()
167     {
168         $files = array(
169             'custom/Extension/modules/relationships/language/application.php' => "<?php\n//THIS FILE IS AUTO GENERATED, DO NOT MODIFY\n"
170                 . "\$app_list_strings['LBL_OPPORTUNITIES_BUGS_1_FROM_OPPORTUNITIES_TITLE'] = 'Opportunities';\n"
171                 . "\$app_list_strings['LBL_OPPORTUNITIES_BUGS_1_FROM_BUGS_TITLE'] ='Bugs';",
172         );
173
174         $labelDefinitions = array(
175             array(
176                 'module' => 'application',
177                 'system_label' => 'LBL_OPPORTUNITIES_BUGS_1_FROM_OPPORTUNITIES_TITLE',
178                 'display_label' => 'Opportunities',
179             ),
180             array(
181                 'module' => 'application',
182                 'system_label' => 'LBL_OPPORTUNITIES_BUGS_1_FROM_BUGS_TITLE',
183                 'display_label' => 'Bugs',
184             ),
185         );
186
187         $this->writeTestFiles($files);
188         $this->uninstallLabels($labelDefinitions);
189
190         $this->assertFileNotExists('custom/Extension/modules/relationships/language/application.php');
191
192     }
193
194     /**
195      * @group 56228
196      */
197     public function testUninstallExtLabels()
198     {
199         $files = array(
200             'custom/Extension/modules/Bugs/Ext/Language/en_us.customopportunities_bugs_1.php' => 'some text',
201             'custom/Extension/modules/Opportunities/Ext/Language/en_us.customopportunities_bugs_1.php' => 'some text',
202             'custom/Extension/application/Ext/Language/en_us.customopportunities_bugs_1.php' => 'some text'
203         );
204         $labelDefinitions = array(
205             array(
206                 'module' => 'Bugs',
207             ),
208             array(
209                 'module' => 'Opportunities',
210             ),
211             array(
212                 'module' => 'application',
213             ),
214         );
215
216         $this->writeTestFiles($files);
217
218         $oModuleInstaller = new ModuleInstaller();
219         $oModuleInstaller->id_name = 'customopportunities_bugs_1';
220         $oModuleInstaller->uninstallExtLabels($labelDefinitions);
221
222         foreach(array_keys($files) as $fileName){
223             $this->assertFileNotExists($fileName);
224         }
225
226     }
227
228     private function uninstallLabels($labelDefinitions)
229     {
230         $oModuleInstaller = new ModuleInstaller();
231         $oModuleInstaller->uninstallLabels('custom/Extension/modules/relationships/language/', $labelDefinitions);
232     }
233
234     private function writeTestFiles($files)
235     {
236         foreach ($files as $fileName => $sContent) {
237             $this->fileNames[] = $fileName;
238
239             if (!file_exists($fileName)){
240                 mkdir_recursive(dirname($fileName));
241             }
242             file_put_contents($fileName, $sContent);
243         }
244     }
245
246     public function tearDown()
247     {
248         foreach ($this->fileNames as $fileNames) {
249             @unlink($fileNames);
250         }
251
252         parent::tearDown();
253     }
254
255 }