]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Studio/RenameModulesTest.php
Release 6.3.0beta4
[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         $rm->save(FALSE);
82
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] );
87
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.");
94
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.");
99
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.');
105     
106         //Ensure we recorded which modules were modified.
107         $renamedModules = $rm->getRenamedModules();
108         $this->assertTrue( count($renamedModules) > 0 );
109
110         $this->removeCustomAppStrings();
111         $this->removeModuleStrings( $renamedModules );
112     }
113
114     public function testRenameNonExistantModule()
115     {
116         $module = 'UnitTestDNEModule';
117         $newSingular = 'UnitTest';
118         $newPlural = 'UnitTests';
119
120         $rm = new RenameModules();
121
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;
130
131         $rm->save(FALSE);
132
133         //Ensure no modules were modified
134         $renamedModules = $rm->getRenamedModules();
135         $this->assertTrue( count($renamedModules) == 0 );
136
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] );
141          
142     }
143
144
145     private function removeCustomAppStrings()
146     {
147         $fileName = 'custom'. DIRECTORY_SEPARATOR . 'include'. DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR . $this->language . '.lang.php';
148         if( file_exists($fileName) )
149         {
150             @unlink($fileName);
151         }
152     }
153
154     private function removeModuleStrings($modules)
155     {
156         foreach($modules as $module => $v)
157         {
158             $fileName = 'custom'. DIRECTORY_SEPARATOR . 'modules'. DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR . $this->language . '.lang.php';
159             if( file_exists($fileName) )
160             {
161                 @unlink($fileName);
162             }
163
164         }
165
166     }
167
168 }