]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Studio/RenameModulesTest.php
Release 6.3.1
[Github/sugarcrm.git] / tests / modules / Studio / RenameModulesTest.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
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.
12  * 
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
16  * details.
17  * 
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
21  * 02110-1301 USA.
22  * 
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.
25  * 
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.
29  * 
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  ********************************************************************************/
36
37
38 require_once('modules/Studio/wizards/RenameModules.php');
39
40
41 class RenameModulesTest extends Sugar_PHPUnit_Framework_TestCase
42 {
43     private $language;
44
45     public function setup()
46     {
47         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
48         $this->language = 'en_us';
49     }
50
51     public function tearDown()
52     {
53         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
54         unset($GLOBALS['current_user']);
55     }
56
57
58     public function testGetRenamedModules()
59     {
60         $rm = new RenameModules();
61         $this->assertEquals(0, count($rm->getRenamedModules()) );
62     }
63
64     
65     public function testRenameContactsModule()
66     {
67         $module = 'Accounts';
68         $newSingular = 'Company';
69         $newPlural = 'Companies';
70
71         $rm = new RenameModules();
72
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';
80
81         global $app_list_strings;
82         if (!isset($app_list_strings['parent_type_display'][$module])) {
83             $app_list_strings['parent_type_display'][$module] = 'Account';
84         }
85         $rm->save(FALSE);
86
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] );
92
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.");
99
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.");
104
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.');
110     
111         //Ensure we recorded which modules were modified.
112         $renamedModules = $rm->getRenamedModules();
113         $this->assertTrue( count($renamedModules) > 0 );
114
115         $this->removeCustomAppStrings();
116         $this->removeModuleStrings( $renamedModules );
117     }
118
119     public function testRenameNonExistantModule()
120     {
121         $module = 'UnitTestDNEModule';
122         $newSingular = 'UnitTest';
123         $newPlural = 'UnitTests';
124
125         $rm = new RenameModules();
126
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;
135
136         $rm->save(FALSE);
137
138         //Ensure no modules were modified
139         $renamedModules = $rm->getRenamedModules();
140         $this->assertTrue( count($renamedModules) == 0 );
141
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] ));
146          
147     }
148
149
150     private function removeCustomAppStrings()
151     {
152         $fileName = 'custom'. DIRECTORY_SEPARATOR . 'include'. DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR . $this->language . '.lang.php';
153         if( file_exists($fileName) )
154         {
155             @unlink($fileName);
156         }
157     }
158
159     private function removeModuleStrings($modules)
160     {
161         foreach($modules as $module => $v)
162         {
163             $fileName = 'custom'. DIRECTORY_SEPARATOR . 'modules'. DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR . $this->language . '.lang.php';
164             if( file_exists($fileName) )
165             {
166                 @unlink($fileName);
167             }
168
169         }
170
171     }
172
173     /**
174      * @group bug46880
175      * making sure subpanel is not renamed twice by both plural name and singular name
176      */
177     public function testSubpanelRenaming()
178     {
179         $module = 'Accounts';
180         $newSingular = 'Account1';
181         $newPlural = 'Accounts2';
182
183         $rm = new RenameModules();
184
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';
192
193         global $app_list_strings;
194         if (!isset($app_list_strings['parent_type_display'][$module])) {
195             $app_list_strings['parent_type_display'][$module] = 'Account';
196         }
197         $rm->save(FALSE);
198
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.");
202
203         //Ensure we recorded which modules were modified.
204         $renamedModules = $rm->getRenamedModules();
205         $this->assertTrue( count($renamedModules) > 0 );
206
207         //cleanup
208         $this->removeCustomAppStrings();
209         $this->removeModuleStrings( $renamedModules );
210     }
211
212     /**
213      * @group bug45804
214      */
215     public function testDashletsRenaming()
216     {
217         $module = 'Accounts';
218         $newSingular = 'Account1';
219         $newPlural = 'Accounts2';
220
221         $rm = new RenameModules();
222
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';
230
231         global $app_list_strings;
232         if (!isset($app_list_strings['parent_type_display'][$module])) {
233             $app_list_strings['parent_type_display'][$module] = 'Account';
234         }
235         $rm->save(FALSE);
236
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.");
240
241         //Ensure we recorded which modules were modified.
242         $renamedModules = $rm->getRenamedModules();
243         $this->assertTrue( count($renamedModules) > 0 );
244
245         //cleanup
246         $this->removeCustomAppStrings();
247         $this->removeModuleStrings( $renamedModules );
248     }
249 }