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/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()
142 'name' => 'some_field_usdoll',
143 'column_key' => 'self::some_field_usdoll',
145 '51568TABLE_SOME_FIELD_USDOLL' => 100500
148 $result = $this->getResults($data);
149 $this->assertEquals('¥100.500,000', $result);
155 public function testFieldCurrencyPlainWithWrongCurrency()
158 'currency_id' => '-51568',
159 'currency_symbol' => '£'
161 $result = $this->getResults($data);
162 $this->assertEquals('¥100.500,000', $result);
165 protected function getResults($layout_def_addon)
168 'column_key' => 'self::some_field',
170 '51568TABLE_SOME_FIELD' => 100500,
172 'name' => 'some_field',
173 'table_key' => 'self',
174 'table_alias' => '51568table',
177 foreach($layout_def_addon as $k => $v)
181 $layout_def = array_merge_recursive($layout_def, array($k => $v));
185 $layout_def[$k] = $v;
188 $sf = $this->getMock('SugarWidgetFieldCurrency',
189 array('getTruncatedColumnAlias'),
191 $sf->expects($this->any())
192 ->method('getTruncatedColumnAlias')
193 ->will($this->returnArgument(0));
194 return $sf->displayListPlain($layout_def);
197 public function tearDown()
199 global $sugar_config;
200 $this->currency_system->symbol = $this->backupSymbol;
201 $this->currency_system->save(false);
202 $sugar_config['default_currency_symbol'] = $this->backupSymbol;
203 $this->currency_51568->mark_deleted($this->currency_51568->id);
204 SugarTestHelper::tearDown();
205 get_number_seperators(true);