2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2013 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/generic/LayoutManager.php';
41 * Currency symbol didn't export to the CVS or pdf file in report module
43 * @author aryamrchik@sugarcrm.com
46 class Bug51568Test extends Sugar_PHPUnit_Framework_TestCase
56 protected $currency_51568;
61 protected $currency_system;
66 protected $backupSymbol;
68 public function setUp()
70 global $current_user, $sugar_config;
71 SugarTestHelper::setUp('current_user', array(true));
72 $current_user->setPreference('dec_sep', ',');
73 $current_user->setPreference('num_grp_sep', '.');
74 $current_user->setPreference('default_currency_significant_digits', 3);
76 SugarTestHelper::setUp('app_list_strings');
77 SugarTestHelper::setUp('beanFiles');
78 SugarTestHelper::setUp('beanList');
81 $this->lm = new LayoutManager();
82 $this->lm->setAttribute('reporter', new stdClass());
84 $this->currency_51568 = new Currency();
85 $this->currency_51568->symbol = 'TT';
86 $this->currency_51568->conversion_rate = 0.5;
87 $this->currency_51568->save(false);
88 $this->currency_system = new Currency();
89 $this->currency_system->retrieve(-99);
90 $this->backupSymbol = $this->currency_system->symbol;
91 $this->currency_system->symbol = '¥';
92 $this->currency_system->save(false);
93 $sugar_config['default_currency_symbol'] = '¥';
94 get_number_seperators(true);
100 public function testFieldCurrencyPlainWithLayoutDef()
103 'currency_id' => $this->currency_51568->id,
104 'currency_symbol' => $this->currency_51568->symbol
106 $result = $this->getResults($data);
107 $this->assertEquals('TT100.500,000', $result);
113 public function testFieldCurrencyPlainWithCurrencyField()
117 '51568table_some_field_currency' => $this->currency_51568->id)
119 $result = $this->getResults($data);
120 $this->assertEquals('TT100.500,000', $result);
126 public function testFieldCurrencyPlainWithAnotherCurrencyField()
130 '51568TABLE_SOME_FIELD_CURRENCY' => $this->currency_51568->id)
132 $result = $this->getResults($data);
133 $this->assertEquals('TT100.500,000', $result);
139 public function testFieldCurrencyPlainWithSystemCurrencyField()
141 format_number(0, 0, 0, array(
142 'currency_id' => $this->currency_51568->id,
143 'currency_symbol' => $this->currency_51568->symbol
146 format_number(0, 0, 0, array(
147 'currency_id' => -99,
148 'currency_symbol' => $this->currency_51568->getDefaultCurrencySymbol()
152 'name' => 'some_field_usdoll',
153 'column_key' => 'self::some_field_usdoll',
155 '51568TABLE_SOME_FIELD_USDOLL' => 100500
158 $result = $this->getResults($data);
159 $this->assertEquals('¥100.500,000', $result);
165 public function testFieldCurrencyPlainWithWrongCurrency()
168 'currency_id' => '-51568',
169 'currency_symbol' => '£'
171 $result = $this->getResults($data);
172 $this->assertEquals('¥100.500,000', $result);
175 protected function getResults($layout_def_addon)
178 'column_key' => 'self::some_field',
180 '51568TABLE_SOME_FIELD' => 100500,
182 'name' => 'some_field',
183 'table_key' => 'self',
184 'table_alias' => '51568table',
187 foreach($layout_def_addon as $k => $v)
191 $layout_def = array_merge_recursive($layout_def, array($k => $v));
195 $layout_def[$k] = $v;
198 $sf = $this->getMock('SugarWidgetFieldCurrency',
199 array('getTruncatedColumnAlias'),
201 $sf->expects($this->any())
202 ->method('getTruncatedColumnAlias')
203 ->will($this->returnArgument(0));
204 return $sf->displayListPlain($layout_def);
207 public function tearDown()
209 global $sugar_config;
210 $this->currency_system->symbol = $this->backupSymbol;
211 $this->currency_system->save(false);
212 $sugar_config['default_currency_symbol'] = $this->backupSymbol;
214 format_number(0, 0, 0, array(
215 'currency_id' => $this->currency_51568->id,
216 'currency_symbol' => $this->currency_51568->symbol
219 format_number(0, 0, 0, array(
220 'currency_id' => -99,
221 'currency_symbol' => $this->currency_51568->getDefaultCurrencySymbol()
224 $this->currency_51568->mark_deleted($this->currency_51568->id);
225 SugarTestHelper::tearDown();
226 get_number_seperators(true);