]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Studio/RenameModulesTest.php
Release 6.4.0
[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     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         if (!isset($app_list_strings['parent_type_display'][$module])) {
113             $app_list_strings['parent_type_display'][$module] = 'Account';
114         }
115         $rm->save(FALSE);
116
117         //Test app list strings
118         $app_list_string = return_app_list_strings_language('en_us');
119         $this->assertEquals($newSingular, $app_list_string['moduleListSingular'][$module] );
120         $this->assertEquals($newPlural, $app_list_string['moduleList'][$module] );
121         $this->assertEquals($newSingular, $app_list_string['parent_type_display'][$module] );
122
123         //Test module strings for account
124         $accountStrings = return_module_language('en_us','Accounts', TRUE);
125         $this->assertEquals('Create Company', $accountStrings['LNK_NEW_ACCOUNT'], "Rename module failed for modules modStrings.");
126         $this->assertEquals('View Companies', $accountStrings['LNK_ACCOUNT_LIST'], "Rename module failed for modules modStrings.");
127         $this->assertEquals('Import Companies', $accountStrings['LNK_IMPORT_ACCOUNTS'], "Rename module failed for modules modStrings.");
128         $this->assertEquals('Company Search', $accountStrings['LBL_SEARCH_FORM_TITLE'], "Rename module failed for modules modStrings.");
129
130         //Test related link renames
131         $contactStrings = return_module_language('en_us','Contacts', TRUE);
132         $this->assertEquals('Company Name:', $contactStrings['LBL_ACCOUNT_NAME'], "Rename related links failed for module.");
133         $this->assertEquals('Company ID:', $contactStrings['LBL_ACCOUNT_ID'], "Rename related links failed for module.");
134
135         //Test subpanel renames
136         $campaignStrings = return_module_language('en_us','Campaigns', TRUE);
137         $this->assertEquals('Companies', $campaignStrings['LBL_CAMPAIGN_ACCOUNTS_SUBPANEL_TITLE'], "Renaming subpanels failed for module.");
138         // bug 45554: ensure labels are changed
139         $this->assertEquals('Companies', $campaignStrings['LBL_ACCOUNTS'], 'Renaming labels failed for module.');
140
141         //Ensure we recorded which modules were modified.
142         $renamedModules = $rm->getRenamedModules();
143         $this->assertTrue( count($renamedModules) > 0 );
144
145         $this->removeCustomAppStrings();
146         $this->removeModuleStrings( $renamedModules );
147     }
148
149     public function testRenameNonExistantModule()
150     {
151         $module = 'UnitTestDNEModule';
152         $newSingular = 'UnitTest';
153         $newPlural = 'UnitTests';
154
155         $rm = new RenameModules();
156
157         $_REQUEST['slot_0'] = 0;
158         $_REQUEST['key_0'] = $module;
159         $_REQUEST['svalue_0'] = $newSingular;
160         $_REQUEST['value_0'] = $newPlural;
161         $_REQUEST['delete_0'] = '';
162         $_REQUEST['dropdown_lang'] = $this->language;
163         $_REQUEST['dropdown_name'] = 'moduleList';
164         $_REQUEST['use_push'] = TRUE;
165
166         $rm->save(FALSE);
167
168         //Ensure no modules were modified
169         $renamedModules = $rm->getRenamedModules();
170         $this->assertTrue( count($renamedModules) == 0 );
171
172         //Ensure none of the app list strings were modified.
173         $app_list_string = return_app_list_strings_language('en_us');
174         if(isset( $app_list_string['moduleListSingular'][$module])) {
175             $this->assertNotEquals($newSingular, $app_list_string['moduleListSingular'][$module] );
176         }
177         if(isset($app_list_string['moduleList'][$module])) {
178             $this->assertNotEquals($newPlural, $app_list_string['moduleList'][$module] );
179         }
180
181     }
182
183
184     private function removeCustomAppStrings()
185     {
186         $fileName = 'custom'. DIRECTORY_SEPARATOR . 'include'. DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR . $this->language . '.lang.php';
187         if( file_exists($fileName) )
188         {
189             @unlink($fileName);
190         }
191     }
192
193     private function removeModuleStrings($modules)
194     {
195         foreach($modules as $module => $v)
196         {
197             $fileName = 'custom'. DIRECTORY_SEPARATOR . 'modules'. DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR . $this->language . '.lang.php';
198             if( file_exists($fileName) )
199             {
200                 @unlink($fileName);
201             }
202
203         }
204
205     }
206
207     /**
208      * @group bug46880
209      * making sure subpanel is not renamed twice by both plural name and singular name
210      */
211     public function testSubpanelRenaming()
212     {
213         $this->markTestSkipped('Because of bug 47239,  Skipping test.');
214
215         $module = 'Accounts';
216         $newSingular = 'Account1';
217         $newPlural = 'Accounts2';
218
219         $rm = new RenameModules();
220
221         $_REQUEST['slot_0'] = 0;
222         $_REQUEST['key_0'] = $module;
223         $_REQUEST['svalue_0'] = $newSingular;
224         $_REQUEST['value_0'] = $newPlural;
225         $_REQUEST['delete_0'] = '';
226         $_REQUEST['dropdown_lang'] = $this->language;
227         $_REQUEST['dropdown_name'] = 'moduleList';
228
229         global $app_list_strings;
230         if (!isset($app_list_strings['parent_type_display'][$module])) {
231             $app_list_strings['parent_type_display'][$module] = 'Account';
232         }
233         $rm->save(FALSE);
234
235         //Test subpanel renames
236         $bugStrings = return_module_language('en_us','Bugs', TRUE);
237         $this->assertEquals('Accounts2', $bugStrings['LBL_ACCOUNTS_SUBPANEL_TITLE'], "Renaming subpanels failed for module.");
238
239         //Ensure we recorded which modules were modified.
240         $renamedModules = $rm->getRenamedModules();
241         $this->assertTrue( count($renamedModules) > 0 );
242
243         //cleanup
244         $this->removeCustomAppStrings();
245         $this->removeModuleStrings( $renamedModules );
246     }
247
248     /**
249      * @group bug45804
250      */
251     public function testDashletsRenaming()
252     {
253         $this->markTestSkipped('Because of bug 47239,  Skipping test.');
254
255         $module = 'Accounts';
256         $newSingular = 'Account1';
257         $newPlural = 'Accounts2';
258
259         $rm = new RenameModules();
260
261         $_REQUEST['slot_0'] = 0;
262         $_REQUEST['key_0'] = $module;
263         $_REQUEST['svalue_0'] = $newSingular;
264         $_REQUEST['value_0'] = $newPlural;
265         $_REQUEST['delete_0'] = '';
266         $_REQUEST['dropdown_lang'] = $this->language;
267         $_REQUEST['dropdown_name'] = 'moduleList';
268
269         global $app_list_strings;
270         if (!isset($app_list_strings['parent_type_display'][$module])) {
271             $app_list_strings['parent_type_display'][$module] = 'Account';
272         }
273         $rm->save(FALSE);
274
275         //Test dashlets renames
276         $callStrings = return_module_language('en_us', 'Accounts', TRUE);
277         $this->assertEquals('My Accounts2', $callStrings['LBL_HOMEPAGE_TITLE'], "Renaming dashlets failed for module.");
278
279         //Ensure we recorded which modules were modified.
280         $renamedModules = $rm->getRenamedModules();
281         $this->assertTrue( count($renamedModules) > 0 );
282
283         //cleanup
284         $this->removeCustomAppStrings();
285         $this->removeModuleStrings( $renamedModules );
286     }
287 }