]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Studio/RenameModulesTest.php
Release 6.5.10
[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-2013 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     private $language_contents;
45
46     public function setup()
47     {
48         $mods = array('Accounts', 'Contacts', 'Campaigns');
49         foreach($mods as $mod)
50         {
51             if(file_exists("custom/modules/{$mod}/language/en_us.lang.php"))
52             {
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");
55             }
56         }
57
58         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
59         $this->language = 'en_us';
60
61         $beanList = array();
62         $beanFiles = array();
63         require('include/modules.php');
64         $GLOBALS['beanList'] = $beanList;
65         $GLOBALS['beanFiles'] = $beanFiles;
66     }
67
68     public function tearDown()
69     {
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;
77
78         if(!empty($this->language_contents))
79         {
80             foreach($this->language_contents as $key=>$contents)
81             {
82                 sugar_file_put_contents("custom/modules/{$key}/language/en_us.lang.php", $contents);
83             }
84         }
85     }
86
87
88     public function testGetRenamedModules()
89     {
90         $rm = new RenameModules();
91         $this->assertEquals(0, count($rm->getRenamedModules()) );
92     }
93
94
95     public function testRenameContactsModule()
96     {
97         $module = 'Accounts';
98         $newSingular = 'Company';
99         $newPlural = 'Companies';
100
101         $rm = new RenameModules();
102
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';
110
111         global $app_list_strings;
112         
113         foreach(getTypeDisplayList() as $typeDisplay) 
114         {
115             if (!isset($app_list_strings[$typeDisplay][$module])) 
116             {
117                 $app_list_strings[$typeDisplay][$module] = 'Account';
118             }
119         }
120         
121         $rm->save(FALSE);
122
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) 
128         {
129             $this->assertEquals($newSingular, $app_list_string[$typeDisplay][$module] );
130         }
131
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.");
138
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.");
143
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.');
149
150         //Ensure we recorded which modules were modified.
151         $renamedModules = $rm->getRenamedModules();
152         $this->assertTrue( count($renamedModules) > 0 );
153
154         $this->removeCustomAppStrings();
155         $this->removeModuleStrings( $renamedModules );
156     }
157
158     public function testRenameNonExistantModule()
159     {
160         $module = 'UnitTestDNEModule';
161         $newSingular = 'UnitTest';
162         $newPlural = 'UnitTests';
163
164         $rm = new RenameModules();
165
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;
174
175         $rm->save(FALSE);
176
177         //Ensure no modules were modified
178         $renamedModules = $rm->getRenamedModules();
179         $this->assertTrue( count($renamedModules) == 0 );
180
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] );
185         }
186         if(isset($app_list_string['moduleList'][$module])) {
187             $this->assertNotEquals($newPlural, $app_list_string['moduleList'][$module] );
188         }
189
190     }
191
192
193     private function removeCustomAppStrings()
194     {
195         $fileName = 'custom'. DIRECTORY_SEPARATOR . 'include'. DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR . $this->language . '.lang.php';
196         if( file_exists($fileName) )
197         {
198             @unlink($fileName);
199         }
200     }
201
202     private function removeModuleStrings($modules)
203     {
204         foreach($modules as $module => $v)
205         {
206             $fileName = 'custom'. DIRECTORY_SEPARATOR . 'modules'. DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR . $this->language . '.lang.php';
207             if( file_exists($fileName) )
208             {
209                 @unlink($fileName);
210             }
211
212         }
213
214     }
215
216     /**
217      * @group bug46880
218      * making sure subpanel is not renamed twice by both plural name and singular name
219      */
220     public function testSubpanelRenaming()
221     {
222         $this->markTestIncomplete('Because of bug 47239,  Skipping test.');
223
224         $module = 'Accounts';
225         $newSingular = 'Account1';
226         $newPlural = 'Accounts2';
227
228         $rm = new RenameModules();
229
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';
237
238         global $app_list_strings;
239
240         foreach(getTypeDisplayList() as $typeDisplay) 
241         {
242             if (!isset($app_list_strings[$typeDisplay][$module])) 
243             {
244                 $app_list_strings[$typeDisplay][$module] = 'Account';
245             }
246         }
247         $rm->save(FALSE);
248
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.");
252
253         //Ensure we recorded which modules were modified.
254         $renamedModules = $rm->getRenamedModules();
255         $this->assertTrue( count($renamedModules) > 0 );
256
257         //cleanup
258         $this->removeCustomAppStrings();
259         $this->removeModuleStrings( $renamedModules );
260     }
261
262     /**
263      * @group bug45804
264      */
265     public function testDashletsRenaming()
266     {
267         $this->markTestSkipped('Because of bug 47239,  Skipping test.');
268
269         $module = 'Accounts';
270         $newSingular = 'Account1';
271         $newPlural = 'Accounts2';
272
273         $rm = new RenameModules();
274
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';
282
283         global $app_list_strings;
284         
285         foreach(getTypeDisplayList() as $typeDisplay) 
286         {
287             if (!isset($app_list_strings[$typeDisplay][$module])) 
288             {
289                 $app_list_strings[$typeDisplay][$module] = 'Account';
290             }
291         }
292         $rm->save(FALSE);
293
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.");
297
298         //Ensure we recorded which modules were modified.
299         $renamedModules = $rm->getRenamedModules();
300         $this->assertTrue( count($renamedModules) > 0 );
301
302         //cleanup
303         $this->removeCustomAppStrings();
304         $this->removeModuleStrings( $renamedModules );
305     }
306 }