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';
83 //Test app list strings
84 $app_list_string = return_app_list_strings_language('en_us');
85 $this->assertEquals($newSingular, $app_list_string['moduleListSingular'][$module] );
86 $this->assertEquals($newPlural, $app_list_string['moduleList'][$module] );
88 //Test module strings for account
89 $accountStrings = return_module_language('en_us',$module, TRUE);
90 $this->assertEquals('Create Company', $accountStrings['LNK_NEW_ACCOUNT'], "Rename module failed for modules modStrings.");
91 $this->assertEquals('View Companies', $accountStrings['LNK_ACCOUNT_LIST'], "Rename module failed for modules modStrings.");
92 $this->assertEquals('Import Companies', $accountStrings['LNK_IMPORT_ACCOUNTS'], "Rename module failed for modules modStrings.");
93 $this->assertEquals('Company Search', $accountStrings['LBL_SEARCH_FORM_TITLE'], "Rename module failed for modules modStrings.");
95 //Test related link renames
96 $contactStrings = return_module_language('en_us','Contacts', TRUE);
97 $this->assertEquals('Company Name:', $contactStrings['LBL_ACCOUNT_NAME'], "Rename related links failed for module.");
98 $this->assertEquals('Company ID:', $contactStrings['LBL_ACCOUNT_ID'], "Rename related links failed for module.");
100 //Test subpanel renames
101 $campaignStrings = return_module_language('en_us','Campaigns', TRUE);
102 $this->assertEquals('Companies', $campaignStrings['LBL_CAMPAIGN_ACCOUNTS_SUBPANEL_TITLE'], "Renaming subpanels failed for module.");
103 // bug 45554: ensure labels are changed
104 $this->assertEquals('Companies', $campaignStrings['LBL_ACCOUNTS'], 'Renaming labels failed for module.');
106 //Ensure we recorded which modules were modified.
107 $renamedModules = $rm->getRenamedModules();
108 $this->assertTrue( count($renamedModules) > 0 );
110 $this->removeCustomAppStrings();
111 $this->removeModuleStrings( $renamedModules );
114 public function testRenameNonExistantModule()
116 $module = 'UnitTestDNEModule';
117 $newSingular = 'UnitTest';
118 $newPlural = 'UnitTests';
120 $rm = new RenameModules();
122 $_REQUEST['slot_0'] = 0;
123 $_REQUEST['key_0'] = $module;
124 $_REQUEST['svalue_0'] = $newSingular;
125 $_REQUEST['value_0'] = $newPlural;
126 $_REQUEST['delete_0'] = '';
127 $_REQUEST['dropdown_lang'] = $this->language;
128 $_REQUEST['dropdown_name'] = 'moduleList';
129 $_REQUEST['use_push'] = TRUE;
133 //Ensure no modules were modified
134 $renamedModules = $rm->getRenamedModules();
135 $this->assertTrue( count($renamedModules) == 0 );
137 //Ensure none of the app list strings were modified.
138 $app_list_string = return_app_list_strings_language('en_us');
139 $this->assertNotEquals($newSingular, $app_list_string['moduleListSingular'][$module] );
140 $this->assertNotEquals($newPlural, $app_list_string['moduleList'][$module] );
145 private function removeCustomAppStrings()
147 $fileName = 'custom'. DIRECTORY_SEPARATOR . 'include'. DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR . $this->language . '.lang.php';
148 if( file_exists($fileName) )
154 private function removeModuleStrings($modules)
156 foreach($modules as $module => $v)
158 $fileName = 'custom'. DIRECTORY_SEPARATOR . 'modules'. DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR . $this->language . '.lang.php';
159 if( file_exists($fileName) )