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 require_once('modules/Studio/wizards/RenameModules.php');
41 class RenameModulesTest extends Sugar_PHPUnit_Framework_TestCase
44 private $language_contents;
46 public function setup()
48 $mods = array('Accounts', 'Contacts', 'Campaigns');
49 foreach($mods as $mod)
51 if(file_exists("custom/modules/{$mod}/language/en_us.lang.php"))
53 $this->language_contents[$mod] = file_get_contents("custom/modules/{$mod}/language/en_us.lang.php");
54 unlink("custom/modules/{$mod}/language/en_us.lang.php");
58 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
59 $this->language = 'en_us';
63 require('include/modules.php');
64 $GLOBALS['beanList'] = $beanList;
65 $GLOBALS['beanFiles'] = $beanFiles;
68 public function tearDown()
70 $this->removeCustomAppStrings();
71 $this->removeModuleStrings(array('Accounts'));
72 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
73 unset($GLOBALS['current_user']);
74 unset($GLOBALS['beanList']);
75 unset($GLOBALS['beanFiles']);
76 SugarCache::$isCacheReset = false;
78 if(!empty($this->language_contents))
80 foreach($this->language_contents as $key=>$contents)
82 sugar_file_put_contents("custom/modules/{$key}/language/en_us.lang.php", $contents);
88 public function testGetRenamedModules()
90 $rm = new RenameModules();
91 $this->assertEquals(0, count($rm->getRenamedModules()) );
95 public function testRenameContactsModule()
98 $newSingular = 'Company';
99 $newPlural = 'Companies';
101 $rm = new RenameModules();
103 $_REQUEST['slot_0'] = 0;
104 $_REQUEST['key_0'] = $module;
105 $_REQUEST['svalue_0'] = $newSingular;
106 $_REQUEST['value_0'] = $newPlural;
107 $_REQUEST['delete_0'] = '';
108 $_REQUEST['dropdown_lang'] = $this->language;
109 $_REQUEST['dropdown_name'] = 'moduleList';
111 global $app_list_strings;
112 if (!isset($app_list_strings['parent_type_display'][$module])) {
113 $app_list_strings['parent_type_display'][$module] = 'Account';
117 //Test app list strings
118 $app_list_string = return_app_list_strings_language('en_us');
119 $this->assertEquals($newSingular, $app_list_string['moduleListSingular'][$module] );
120 $this->assertEquals($newPlural, $app_list_string['moduleList'][$module] );
121 $this->assertEquals($newSingular, $app_list_string['parent_type_display'][$module] );
123 //Test module strings for account
124 $accountStrings = return_module_language('en_us','Accounts', TRUE);
125 $this->assertEquals('Create Company', $accountStrings['LNK_NEW_ACCOUNT'], "Rename module failed for modules modStrings.");
126 $this->assertEquals('View Companies', $accountStrings['LNK_ACCOUNT_LIST'], "Rename module failed for modules modStrings.");
127 $this->assertEquals('Import Companies', $accountStrings['LNK_IMPORT_ACCOUNTS'], "Rename module failed for modules modStrings.");
128 $this->assertEquals('Company Search', $accountStrings['LBL_SEARCH_FORM_TITLE'], "Rename module failed for modules modStrings.");
130 //Test related link renames
131 $contactStrings = return_module_language('en_us','Contacts', TRUE);
132 $this->assertEquals('Company Name:', $contactStrings['LBL_ACCOUNT_NAME'], "Rename related links failed for module.");
133 $this->assertEquals('Company ID:', $contactStrings['LBL_ACCOUNT_ID'], "Rename related links failed for module.");
135 //Test subpanel renames
136 $campaignStrings = return_module_language('en_us','Campaigns', TRUE);
137 $this->assertEquals('Companies', $campaignStrings['LBL_CAMPAIGN_ACCOUNTS_SUBPANEL_TITLE'], "Renaming subpanels failed for module.");
138 // bug 45554: ensure labels are changed
139 $this->assertEquals('Companies', $campaignStrings['LBL_ACCOUNTS'], 'Renaming labels failed for module.');
141 //Ensure we recorded which modules were modified.
142 $renamedModules = $rm->getRenamedModules();
143 $this->assertTrue( count($renamedModules) > 0 );
145 $this->removeCustomAppStrings();
146 $this->removeModuleStrings( $renamedModules );
149 public function testRenameNonExistantModule()
151 $module = 'UnitTestDNEModule';
152 $newSingular = 'UnitTest';
153 $newPlural = 'UnitTests';
155 $rm = new RenameModules();
157 $_REQUEST['slot_0'] = 0;
158 $_REQUEST['key_0'] = $module;
159 $_REQUEST['svalue_0'] = $newSingular;
160 $_REQUEST['value_0'] = $newPlural;
161 $_REQUEST['delete_0'] = '';
162 $_REQUEST['dropdown_lang'] = $this->language;
163 $_REQUEST['dropdown_name'] = 'moduleList';
164 $_REQUEST['use_push'] = TRUE;
168 //Ensure no modules were modified
169 $renamedModules = $rm->getRenamedModules();
170 $this->assertTrue( count($renamedModules) == 0 );
172 //Ensure none of the app list strings were modified.
173 $app_list_string = return_app_list_strings_language('en_us');
174 if(isset( $app_list_string['moduleListSingular'][$module])) {
175 $this->assertNotEquals($newSingular, $app_list_string['moduleListSingular'][$module] );
177 if(isset($app_list_string['moduleList'][$module])) {
178 $this->assertNotEquals($newPlural, $app_list_string['moduleList'][$module] );
184 private function removeCustomAppStrings()
186 $fileName = 'custom'. DIRECTORY_SEPARATOR . 'include'. DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR . $this->language . '.lang.php';
187 if( file_exists($fileName) )
193 private function removeModuleStrings($modules)
195 foreach($modules as $module => $v)
197 $fileName = 'custom'. DIRECTORY_SEPARATOR . 'modules'. DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR . $this->language . '.lang.php';
198 if( file_exists($fileName) )
209 * making sure subpanel is not renamed twice by both plural name and singular name
211 public function testSubpanelRenaming()
213 $this->markTestSkipped('Because of bug 47239, Skipping test.');
215 $module = 'Accounts';
216 $newSingular = 'Account1';
217 $newPlural = 'Accounts2';
219 $rm = new RenameModules();
221 $_REQUEST['slot_0'] = 0;
222 $_REQUEST['key_0'] = $module;
223 $_REQUEST['svalue_0'] = $newSingular;
224 $_REQUEST['value_0'] = $newPlural;
225 $_REQUEST['delete_0'] = '';
226 $_REQUEST['dropdown_lang'] = $this->language;
227 $_REQUEST['dropdown_name'] = 'moduleList';
229 global $app_list_strings;
230 if (!isset($app_list_strings['parent_type_display'][$module])) {
231 $app_list_strings['parent_type_display'][$module] = 'Account';
235 //Test subpanel renames
236 $bugStrings = return_module_language('en_us','Bugs', TRUE);
237 $this->assertEquals('Accounts2', $bugStrings['LBL_ACCOUNTS_SUBPANEL_TITLE'], "Renaming subpanels failed for module.");
239 //Ensure we recorded which modules were modified.
240 $renamedModules = $rm->getRenamedModules();
241 $this->assertTrue( count($renamedModules) > 0 );
244 $this->removeCustomAppStrings();
245 $this->removeModuleStrings( $renamedModules );
251 public function testDashletsRenaming()
253 $this->markTestSkipped('Because of bug 47239, Skipping test.');
255 $module = 'Accounts';
256 $newSingular = 'Account1';
257 $newPlural = 'Accounts2';
259 $rm = new RenameModules();
261 $_REQUEST['slot_0'] = 0;
262 $_REQUEST['key_0'] = $module;
263 $_REQUEST['svalue_0'] = $newSingular;
264 $_REQUEST['value_0'] = $newPlural;
265 $_REQUEST['delete_0'] = '';
266 $_REQUEST['dropdown_lang'] = $this->language;
267 $_REQUEST['dropdown_name'] = 'moduleList';
269 global $app_list_strings;
270 if (!isset($app_list_strings['parent_type_display'][$module])) {
271 $app_list_strings['parent_type_display'][$module] = 'Account';
275 //Test dashlets renames
276 $callStrings = return_module_language('en_us', 'Accounts', TRUE);
277 $this->assertEquals('My Accounts2', $callStrings['LBL_HOMEPAGE_TITLE'], "Renaming dashlets failed for module.");
279 //Ensure we recorded which modules were modified.
280 $renamedModules = $rm->getRenamedModules();
281 $this->assertTrue( count($renamedModules) > 0 );
284 $this->removeCustomAppStrings();
285 $this->removeModuleStrings( $renamedModules );