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 ********************************************************************************/
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;
113 foreach(getTypeDisplayList() as $typeDisplay)
115 if (!isset($app_list_strings[$typeDisplay][$module]))
117 $app_list_strings[$typeDisplay][$module] = 'Account';
123 //Test app list strings
124 $app_list_string = return_app_list_strings_language('en_us');
125 $this->assertEquals($newSingular, $app_list_string['moduleListSingular'][$module] );
126 $this->assertEquals($newPlural, $app_list_string['moduleList'][$module] );
127 foreach(getTypeDisplayList() as $typeDisplay)
129 $this->assertEquals($newSingular, $app_list_string[$typeDisplay][$module] );
132 //Test module strings for account
133 $accountStrings = return_module_language('en_us','Accounts', TRUE);
134 $this->assertEquals('Create Company', $accountStrings['LNK_NEW_ACCOUNT'], "Rename module failed for modules modStrings.");
135 $this->assertEquals('View Companies', $accountStrings['LNK_ACCOUNT_LIST'], "Rename module failed for modules modStrings.");
136 $this->assertEquals('Import Companies', $accountStrings['LNK_IMPORT_ACCOUNTS'], "Rename module failed for modules modStrings.");
137 $this->assertEquals('Company Search', $accountStrings['LBL_SEARCH_FORM_TITLE'], "Rename module failed for modules modStrings.");
139 //Test related link renames
140 $contactStrings = return_module_language('en_us','Contacts', TRUE);
141 $this->assertEquals('Company Name:', $contactStrings['LBL_ACCOUNT_NAME'], "Rename related links failed for module.");
142 $this->assertEquals('Company ID:', $contactStrings['LBL_ACCOUNT_ID'], "Rename related links failed for module.");
144 //Test subpanel renames
145 $campaignStrings = return_module_language('en_us','Campaigns', TRUE);
146 $this->assertEquals('Companies', $campaignStrings['LBL_CAMPAIGN_ACCOUNTS_SUBPANEL_TITLE'], "Renaming subpanels failed for module.");
147 // bug 45554: ensure labels are changed
148 $this->assertEquals('Companies', $campaignStrings['LBL_ACCOUNTS'], 'Renaming labels failed for module.');
150 //Ensure we recorded which modules were modified.
151 $renamedModules = $rm->getRenamedModules();
152 $this->assertTrue( count($renamedModules) > 0 );
154 $this->removeCustomAppStrings();
155 $this->removeModuleStrings( $renamedModules );
158 public function testRenameNonExistantModule()
160 $module = 'UnitTestDNEModule';
161 $newSingular = 'UnitTest';
162 $newPlural = 'UnitTests';
164 $rm = new RenameModules();
166 $_REQUEST['slot_0'] = 0;
167 $_REQUEST['key_0'] = $module;
168 $_REQUEST['svalue_0'] = $newSingular;
169 $_REQUEST['value_0'] = $newPlural;
170 $_REQUEST['delete_0'] = '';
171 $_REQUEST['dropdown_lang'] = $this->language;
172 $_REQUEST['dropdown_name'] = 'moduleList';
173 $_REQUEST['use_push'] = TRUE;
177 //Ensure no modules were modified
178 $renamedModules = $rm->getRenamedModules();
179 $this->assertTrue( count($renamedModules) == 0 );
181 //Ensure none of the app list strings were modified.
182 $app_list_string = return_app_list_strings_language('en_us');
183 if(isset( $app_list_string['moduleListSingular'][$module])) {
184 $this->assertNotEquals($newSingular, $app_list_string['moduleListSingular'][$module] );
186 if(isset($app_list_string['moduleList'][$module])) {
187 $this->assertNotEquals($newPlural, $app_list_string['moduleList'][$module] );
193 private function removeCustomAppStrings()
195 $fileName = 'custom'. DIRECTORY_SEPARATOR . 'include'. DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR . $this->language . '.lang.php';
196 if( file_exists($fileName) )
202 private function removeModuleStrings($modules)
204 foreach($modules as $module => $v)
206 $fileName = 'custom'. DIRECTORY_SEPARATOR . 'modules'. DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR . $this->language . '.lang.php';
207 if( file_exists($fileName) )
218 * making sure subpanel is not renamed twice by both plural name and singular name
220 public function testSubpanelRenaming()
222 $this->markTestIncomplete('Because of bug 47239, Skipping test.');
224 $module = 'Accounts';
225 $newSingular = 'Account1';
226 $newPlural = 'Accounts2';
228 $rm = new RenameModules();
230 $_REQUEST['slot_0'] = 0;
231 $_REQUEST['key_0'] = $module;
232 $_REQUEST['svalue_0'] = $newSingular;
233 $_REQUEST['value_0'] = $newPlural;
234 $_REQUEST['delete_0'] = '';
235 $_REQUEST['dropdown_lang'] = $this->language;
236 $_REQUEST['dropdown_name'] = 'moduleList';
238 global $app_list_strings;
240 foreach(getTypeDisplayList() as $typeDisplay)
242 if (!isset($app_list_strings[$typeDisplay][$module]))
244 $app_list_strings[$typeDisplay][$module] = 'Account';
249 //Test subpanel renames
250 $bugStrings = return_module_language('en_us','Bugs', TRUE);
251 $this->assertEquals('Accounts2', $bugStrings['LBL_ACCOUNTS_SUBPANEL_TITLE'], "Renaming subpanels failed for module.");
253 //Ensure we recorded which modules were modified.
254 $renamedModules = $rm->getRenamedModules();
255 $this->assertTrue( count($renamedModules) > 0 );
258 $this->removeCustomAppStrings();
259 $this->removeModuleStrings( $renamedModules );
265 public function testDashletsRenaming()
267 $this->markTestSkipped('Because of bug 47239, Skipping test.');
269 $module = 'Accounts';
270 $newSingular = 'Account1';
271 $newPlural = 'Accounts2';
273 $rm = new RenameModules();
275 $_REQUEST['slot_0'] = 0;
276 $_REQUEST['key_0'] = $module;
277 $_REQUEST['svalue_0'] = $newSingular;
278 $_REQUEST['value_0'] = $newPlural;
279 $_REQUEST['delete_0'] = '';
280 $_REQUEST['dropdown_lang'] = $this->language;
281 $_REQUEST['dropdown_name'] = 'moduleList';
283 global $app_list_strings;
285 foreach(getTypeDisplayList() as $typeDisplay)
287 if (!isset($app_list_strings[$typeDisplay][$module]))
289 $app_list_strings[$typeDisplay][$module] = 'Account';
294 //Test dashlets renames
295 $callStrings = return_module_language('en_us', 'Accounts', TRUE);
296 $this->assertEquals('My Accounts2', $callStrings['LBL_HOMEPAGE_TITLE'], "Renaming dashlets failed for module.");
298 //Ensure we recorded which modules were modified.
299 $renamedModules = $rm->getRenamedModules();
300 $this->assertTrue( count($renamedModules) > 0 );
303 $this->removeCustomAppStrings();
304 $this->removeModuleStrings( $renamedModules );