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
45 public function setup()
47 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
48 $this->language = 'en_us';
51 public function tearDown()
53 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
54 unset($GLOBALS['current_user']);
58 public function testGetRenamedModules()
60 $rm = new RenameModules();
61 $this->assertEquals(0, count($rm->getRenamedModules()) );
65 public function testRenameContactsModule()
68 $newSingular = 'Company';
69 $newPlural = 'Companies';
71 $rm = new RenameModules();
73 $_REQUEST['slot_0'] = 0;
74 $_REQUEST['key_0'] = $module;
75 $_REQUEST['svalue_0'] = $newSingular;
76 $_REQUEST['value_0'] = $newPlural;
77 $_REQUEST['delete_0'] = '';
78 $_REQUEST['dropdown_lang'] = $this->language;
79 $_REQUEST['dropdown_name'] = 'moduleList';
81 global $app_list_strings;
82 if (!isset($app_list_strings['parent_type_display'][$module])) {
83 $app_list_strings['parent_type_display'][$module] = 'Account';
87 //Test app list strings
88 $app_list_string = return_app_list_strings_language('en_us');
89 $this->assertEquals($newSingular, $app_list_string['moduleListSingular'][$module] );
90 $this->assertEquals($newPlural, $app_list_string['moduleList'][$module] );
91 $this->assertEquals($newSingular, $app_list_string['parent_type_display'][$module] );
93 //Test module strings for account
94 $accountStrings = return_module_language('en_us',$module, TRUE);
95 $this->assertEquals('Create Company', $accountStrings['LNK_NEW_ACCOUNT'], "Rename module failed for modules modStrings.");
96 $this->assertEquals('View Companies', $accountStrings['LNK_ACCOUNT_LIST'], "Rename module failed for modules modStrings.");
97 $this->assertEquals('Import Companies', $accountStrings['LNK_IMPORT_ACCOUNTS'], "Rename module failed for modules modStrings.");
98 $this->assertEquals('Company Search', $accountStrings['LBL_SEARCH_FORM_TITLE'], "Rename module failed for modules modStrings.");
100 //Test related link renames
101 $contactStrings = return_module_language('en_us','Contacts', TRUE);
102 $this->assertEquals('Company Name:', $contactStrings['LBL_ACCOUNT_NAME'], "Rename related links failed for module.");
103 $this->assertEquals('Company ID:', $contactStrings['LBL_ACCOUNT_ID'], "Rename related links failed for module.");
105 //Test subpanel renames
106 $campaignStrings = return_module_language('en_us','Campaigns', TRUE);
107 $this->assertEquals('Companies', $campaignStrings['LBL_CAMPAIGN_ACCOUNTS_SUBPANEL_TITLE'], "Renaming subpanels failed for module.");
108 // bug 45554: ensure labels are changed
109 $this->assertEquals('Companies', $campaignStrings['LBL_ACCOUNTS'], 'Renaming labels failed for module.');
111 //Ensure we recorded which modules were modified.
112 $renamedModules = $rm->getRenamedModules();
113 $this->assertTrue( count($renamedModules) > 0 );
115 $this->removeCustomAppStrings();
116 $this->removeModuleStrings( $renamedModules );
119 public function testRenameNonExistantModule()
121 $module = 'UnitTestDNEModule';
122 $newSingular = 'UnitTest';
123 $newPlural = 'UnitTests';
125 $rm = new RenameModules();
127 $_REQUEST['slot_0'] = 0;
128 $_REQUEST['key_0'] = $module;
129 $_REQUEST['svalue_0'] = $newSingular;
130 $_REQUEST['value_0'] = $newPlural;
131 $_REQUEST['delete_0'] = '';
132 $_REQUEST['dropdown_lang'] = $this->language;
133 $_REQUEST['dropdown_name'] = 'moduleList';
134 $_REQUEST['use_push'] = TRUE;
138 //Ensure no modules were modified
139 $renamedModules = $rm->getRenamedModules();
140 $this->assertTrue( count($renamedModules) == 0 );
142 //Ensure none of the app list strings were modified.
143 $app_list_string = return_app_list_strings_language('en_us');
144 $this->assertFalse(isset($app_list_string['moduleListSingular'][$module] ));
145 $this->assertFalse(isset($app_list_string['moduleList'][$module] ));
150 private function removeCustomAppStrings()
152 $fileName = 'custom'. DIRECTORY_SEPARATOR . 'include'. DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR . $this->language . '.lang.php';
153 if( file_exists($fileName) )
159 private function removeModuleStrings($modules)
161 foreach($modules as $module => $v)
163 $fileName = 'custom'. DIRECTORY_SEPARATOR . 'modules'. DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR . $this->language . '.lang.php';
164 if( file_exists($fileName) )
175 * making sure subpanel is not renamed twice by both plural name and singular name
177 public function testSubpanelRenaming()
179 $module = 'Accounts';
180 $newSingular = 'Account1';
181 $newPlural = 'Accounts2';
183 $rm = new RenameModules();
185 $_REQUEST['slot_0'] = 0;
186 $_REQUEST['key_0'] = $module;
187 $_REQUEST['svalue_0'] = $newSingular;
188 $_REQUEST['value_0'] = $newPlural;
189 $_REQUEST['delete_0'] = '';
190 $_REQUEST['dropdown_lang'] = $this->language;
191 $_REQUEST['dropdown_name'] = 'moduleList';
193 global $app_list_strings;
194 if (!isset($app_list_strings['parent_type_display'][$module])) {
195 $app_list_strings['parent_type_display'][$module] = 'Account';
199 //Test subpanel renames
200 $bugStrings = return_module_language('en_us','Bugs', TRUE);
201 $this->assertEquals('Accounts2', $bugStrings['LBL_ACCOUNTS_SUBPANEL_TITLE'], "Renaming subpanels failed for module.");
203 //Ensure we recorded which modules were modified.
204 $renamedModules = $rm->getRenamedModules();
205 $this->assertTrue( count($renamedModules) > 0 );
208 $this->removeCustomAppStrings();
209 $this->removeModuleStrings( $renamedModules );
215 public function testDashletsRenaming()
217 $module = 'Accounts';
218 $newSingular = 'Account1';
219 $newPlural = 'Accounts2';
221 $rm = new RenameModules();
223 $_REQUEST['slot_0'] = 0;
224 $_REQUEST['key_0'] = $module;
225 $_REQUEST['svalue_0'] = $newSingular;
226 $_REQUEST['value_0'] = $newPlural;
227 $_REQUEST['delete_0'] = '';
228 $_REQUEST['dropdown_lang'] = $this->language;
229 $_REQUEST['dropdown_name'] = 'moduleList';
231 global $app_list_strings;
232 if (!isset($app_list_strings['parent_type_display'][$module])) {
233 $app_list_strings['parent_type_display'][$module] = 'Account';
237 //Test dashlets renames
238 $callStrings = return_module_language('en_us', 'Accounts', TRUE);
239 $this->assertEquals('My Accounts2', $callStrings['LBL_HOMEPAGE_TITLE'], "Renaming dashlets failed for module.");
241 //Ensure we recorded which modules were modified.
242 $renamedModules = $rm->getRenamedModules();
243 $this->assertTrue( count($renamedModules) > 0 );
246 $this->removeCustomAppStrings();
247 $this->removeModuleStrings( $renamedModules );