]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/Dashlets/DashletLoadLanguageTest.php
Release 6.2.0
[Github/sugarcrm.git] / tests / include / Dashlets / DashletLoadLanguageTest.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 require_once 'include/Dashlets/Dashlet.php';
38
39 class DashletLoadLanguageTest extends Sugar_PHPUnit_Framework_TestCase
40 {
41     private $_moduleName;
42     
43     public function setup()
44     {
45         $GLOBALS['dashletStrings'] = array();
46         $this->_moduleName = 'TestModuleForDashletLoadLanguageTest'.mt_rand();
47     }
48     
49     public function tearDown()
50     {
51         if ( is_dir("modules/{$this->_moduleName}") )
52             rmdir_recursive("modules/{$this->_moduleName}");
53         if ( is_dir("custom/modules/{$this->_moduleName}") )
54             rmdir_recursive("custom/modules/{$this->_moduleName}");
55         
56         unset($GLOBALS['dashletStrings']);
57         $GLOBALS['current_language'] = $GLOBALS['sugar_config']['default_language'];
58     }
59     
60     public function testCanLoadCurrentLanguageAppStrings() 
61     {
62         $GLOBALS['current_language'] = 'en_us';
63         sugar_mkdir("modules/{$this->_moduleName}/Dashlets/TestModuleDashlet/",null,true);
64         sugar_file_put_contents("modules/{$this->_moduleName}/Dashlets/TestModuleDashlet/TestModuleDashlet.en_us.lang.php",
65             '<?php $dashletStrings["TestModuleDashlet"]["foo"] = "bar"; ?>');
66         
67         $dashlet = new Dashlet(0);
68         $dashlet->loadLanguage('TestModuleDashlet',"modules/{$this->_moduleName}/Dashlets/");
69         
70         $this->assertEquals("bar",$dashlet->dashletStrings["foo"]);
71     }
72     
73     public function testCanLoadCustomLanguageAppStrings() 
74     {
75         $GLOBALS['current_language'] = 'en_us';
76         sugar_mkdir("modules/{$this->_moduleName}/Dashlets/TestModuleDashlet/",null,true);
77         sugar_file_put_contents("modules/{$this->_moduleName}/Dashlets/TestModuleDashlet/TestModuleDashlet.en_us.lang.php",
78             '<?php $dashletStrings["TestModuleDashlet"]["foo"] = "bar"; ?>');
79         create_custom_directory("modules/{$this->_moduleName}/Dashlets/TestModuleDashlet/");
80         sugar_file_put_contents("custom/modules/{$this->_moduleName}/Dashlets/TestModuleDashlet/TestModuleDashlet.en_us.lang.php",
81             '<?php $dashletStrings["TestModuleDashlet"]["foo"] = "barbar"; ?>');
82         
83         $dashlet = new Dashlet(0);
84         $dashlet->loadLanguage('TestModuleDashlet',"modules/{$this->_moduleName}/Dashlets/");
85         
86         $this->assertEquals("barbar",$dashlet->dashletStrings["foo"]);
87     }
88     
89     public function testCanLoadCustomLanguageAppStringsWhenThereIsNoNoncustomLanguageFile() 
90     {
91         $GLOBALS['current_language'] = 'en_us';
92         create_custom_directory("modules/{$this->_moduleName}/Dashlets/TestModuleDashlet/");
93         sugar_file_put_contents("custom/modules/{$this->_moduleName}/Dashlets/TestModuleDashlet/TestModuleDashlet.en_us.lang.php",
94             '<?php $dashletStrings["TestModuleDashlet"]["foo"] = "barbar"; ?>');
95         
96         $dashlet = new Dashlet(0);
97         $dashlet->loadLanguage('TestModuleDashlet',"modules/{$this->_moduleName}/Dashlets/");
98         
99         $this->assertEquals("barbar",$dashlet->dashletStrings["foo"]);
100     }
101     
102     public function testCanLoadCurrentLanguageAppStringsWhenNotEnglish() 
103     {
104         $GLOBALS['current_language'] = 'FR_fr';
105         sugar_mkdir("modules/{$this->_moduleName}/Dashlets/TestModuleDashlet/",null,true);
106         sugar_file_put_contents("modules/{$this->_moduleName}/Dashlets/TestModuleDashlet/TestModuleDashlet.en_us.lang.php",
107             '<?php $dashletStrings["TestModuleDashlet"]["foo"] = "bar"; ?>');
108         sugar_mkdir("modules/{$this->_moduleName}/Dashlets/TestModuleDashlet/",null,true);
109         sugar_file_put_contents("modules/{$this->_moduleName}/Dashlets/TestModuleDashlet/TestModuleDashlet.FR_fr.lang.php",
110             '<?php $dashletStrings["TestModuleDashlet"]["foo"] = "barrie"; ?>');
111         
112         $dashlet = new Dashlet(0);
113         $dashlet->loadLanguage('TestModuleDashlet',"modules/{$this->_moduleName}/Dashlets/");
114         
115         $this->assertEquals("barrie",$dashlet->dashletStrings["foo"]);
116     }
117     
118     public function testCanLoadEnglishLanguageAppStringsWhenCurrentLanguageDoesNotExist() 
119     {
120         $GLOBALS['current_language'] = 'FR_fr';
121         sugar_mkdir("modules/{$this->_moduleName}/Dashlets/TestModuleDashlet/",null,true);
122         sugar_file_put_contents("modules/{$this->_moduleName}/Dashlets/TestModuleDashlet/TestModuleDashlet.en_us.lang.php",
123             '<?php $dashletStrings["TestModuleDashlet"]["foo"] = "bar"; ?>');
124         
125         $dashlet = new Dashlet(0);
126         $dashlet->loadLanguage('TestModuleDashlet',"modules/{$this->_moduleName}/Dashlets/");
127         
128         $this->assertEquals("bar",$dashlet->dashletStrings["foo"]);
129     }
130     
131     public function testCanLoadCustomEnglishLanguageAppStringsWhenCurrentLanguageDoesNotExist() 
132     {
133         $GLOBALS['current_language'] = 'FR_fr';
134         sugar_mkdir("modules/{$this->_moduleName}/Dashlets/TestModuleDashlet/",null,true);
135         sugar_file_put_contents("modules/{$this->_moduleName}/Dashlets/TestModuleDashlet/TestModuleDashlet.en_us.lang.php",
136             '<?php $dashletStrings["TestModuleDashlet"]["foo"] = "bar"; ?>');
137         create_custom_directory("modules/{$this->_moduleName}/Dashlets/TestModuleDashlet/");
138         sugar_file_put_contents("custom/modules/{$this->_moduleName}/Dashlets/TestModuleDashlet/TestModuleDashlet.en_us.lang.php",
139             '<?php $dashletStrings["TestModuleDashlet"]["foo"] = "barbarbar"; ?>');
140         
141         $dashlet = new Dashlet(0);
142         $dashlet->loadLanguage('TestModuleDashlet',"modules/{$this->_moduleName}/Dashlets/");
143         
144         $this->assertEquals("barbarbar",$dashlet->dashletStrings["foo"]);
145     }
146 }