2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
37 require_once 'include/Dashlets/Dashlet.php';
39 class DashletLoadLanguageTest extends Sugar_PHPUnit_Framework_TestCase
43 public function setup()
45 $GLOBALS['dashletStrings'] = array();
46 $this->_moduleName = 'TestModuleForDashletLoadLanguageTest'.mt_rand();
49 public function tearDown()
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}");
56 unset($GLOBALS['dashletStrings']);
57 $GLOBALS['current_language'] = $GLOBALS['sugar_config']['default_language'];
60 public function testCanLoadCurrentLanguageAppStrings()
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"; ?>');
67 $dashlet = new Dashlet(0);
68 $dashlet->loadLanguage('TestModuleDashlet',"modules/{$this->_moduleName}/Dashlets/");
70 $this->assertEquals("bar",$dashlet->dashletStrings["foo"]);
73 public function testCanLoadCustomLanguageAppStrings()
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"; ?>');
83 $dashlet = new Dashlet(0);
84 $dashlet->loadLanguage('TestModuleDashlet',"modules/{$this->_moduleName}/Dashlets/");
86 $this->assertEquals("barbar",$dashlet->dashletStrings["foo"]);
89 public function testCanLoadCustomLanguageAppStringsWhenThereIsNoNoncustomLanguageFile()
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"; ?>');
96 $dashlet = new Dashlet(0);
97 $dashlet->loadLanguage('TestModuleDashlet',"modules/{$this->_moduleName}/Dashlets/");
99 $this->assertEquals("barbar",$dashlet->dashletStrings["foo"]);
102 public function testCanLoadCurrentLanguageAppStringsWhenNotEnglish()
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"; ?>');
112 $dashlet = new Dashlet(0);
113 $dashlet->loadLanguage('TestModuleDashlet',"modules/{$this->_moduleName}/Dashlets/");
115 $this->assertEquals("barrie",$dashlet->dashletStrings["foo"]);
118 public function testCanLoadEnglishLanguageAppStringsWhenCurrentLanguageDoesNotExist()
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"; ?>');
125 $dashlet = new Dashlet(0);
126 $dashlet->loadLanguage('TestModuleDashlet',"modules/{$this->_moduleName}/Dashlets/");
128 $this->assertEquals("bar",$dashlet->dashletStrings["foo"]);
131 public function testCanLoadCustomEnglishLanguageAppStringsWhenCurrentLanguageDoesNotExist()
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"; ?>');
141 $dashlet = new Dashlet(0);
142 $dashlet->loadLanguage('TestModuleDashlet',"modules/{$this->_moduleName}/Dashlets/");
144 $this->assertEquals("barbarbar",$dashlet->dashletStrings["foo"]);