2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2013 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 ********************************************************************************/
39 require_once('ModuleInstall/ModuleInstaller.php');
42 class Bug56228Test extends Sugar_PHPUnit_Framework_TestCase
49 public function testUninstallNoFilesModStr()
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';",
59 $labelDefinitions = array(
62 'system_label' => 'LBL_OPPORTUNITIES_BUGS_1_FROM_OPPORTUNITIES_TITLE',
63 'display_label' => 'Opportunities',
66 'module' => 'Opportunities',
67 'system_label' => 'LBL_OPPORTUNITIES_BUGS_1_FROM_BUGS_TITLE',
68 'display_label' => 'Bugs',
72 $this->writeTestFiles($files);
73 $this->uninstallLabels($labelDefinitions);
75 $this->assertFileNotExists(
76 'custom/Extension/modules/relationships/language/Bugs.php',
77 'Not deleted empty file'
79 $this->assertFileNotExists(
80 'custom/Extension/modules/relationships/language/Opportunities.php',
81 'Not deleted empty file'
89 public function testUninstallWithFilesModStr()
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';",
100 $labelDefinitions = array(
103 'system_label' => 'LBL_OPPORTUNITIES_BUGS_1_FROM_OPPORTUNITIES_TITLE',
104 'display_label' => 'Opportunities',
107 'module' => 'Opportunities',
108 'system_label' => 'LBL_OPPORTUNITIES_BUGS_1_FROM_BUGS_TITLE',
109 'display_label' => 'Bugs',
113 $this->writeTestFiles($files);
114 $this->uninstallLabels($labelDefinitions);
117 $this->assertFileNotExists('custom/Extension/modules/relationships/language/Opportunities.php');
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);
129 public function testUninstallWithFilesAppStr()
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';",
138 $labelDefinitions = array(
140 'module' => 'application',
141 'system_label' => 'LBL_OPPORTUNITIES_BUGS_1_FROM_OPPORTUNITIES_TITLE',
142 'display_label' => 'Opportunities',
146 'module' => 'application',
147 'system_label' => 'LBL_OPPORTUNITIES_BUGS_1_FROM_BUGS_TITLE',
148 'display_label' => 'Bugs',
153 $this->writeTestFiles($files);
154 $this->uninstallLabels($labelDefinitions);
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);
166 public function testUninstallNoFilesAppStr()
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';",
174 $labelDefinitions = array(
176 'module' => 'application',
177 'system_label' => 'LBL_OPPORTUNITIES_BUGS_1_FROM_OPPORTUNITIES_TITLE',
178 'display_label' => 'Opportunities',
181 'module' => 'application',
182 'system_label' => 'LBL_OPPORTUNITIES_BUGS_1_FROM_BUGS_TITLE',
183 'display_label' => 'Bugs',
187 $this->writeTestFiles($files);
188 $this->uninstallLabels($labelDefinitions);
190 $this->assertFileNotExists('custom/Extension/modules/relationships/language/application.php');
197 public function testUninstallExtLabels()
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'
204 $labelDefinitions = array(
209 'module' => 'Opportunities',
212 'module' => 'application',
216 $this->writeTestFiles($files);
218 $oModuleInstaller = new ModuleInstaller();
219 $oModuleInstaller->id_name = 'customopportunities_bugs_1';
220 $oModuleInstaller->uninstallExtLabels($labelDefinitions);
222 foreach(array_keys($files) as $fileName){
223 $this->assertFileNotExists($fileName);
228 private function uninstallLabels($labelDefinitions)
230 $oModuleInstaller = new ModuleInstaller();
231 $oModuleInstaller->uninstallLabels('custom/Extension/modules/relationships/language/', $labelDefinitions);
234 private function writeTestFiles($files)
236 foreach ($files as $fileName => $sContent) {
237 $this->fileNames[] = $fileName;
239 if (!file_exists($fileName)){
240 mkdir_recursive(dirname($fileName));
242 file_put_contents($fileName, $sContent);
246 public function tearDown()
248 foreach ($this->fileNames as $fileNames) {