]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/generic/SugarWidgets/Bug51568Test.php
Release 6.5.10
[Github/sugarcrm.git] / tests / include / generic / SugarWidgets / Bug51568Test.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2013 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/generic/LayoutManager.php';
38
39 /**
40  * Bug #51568
41  *  Currency symbol didn't export to the CVS or pdf file in report module
42  *
43  * @author aryamrchik@sugarcrm.com
44  * @ticket 51568
45  */
46 class Bug51568Test extends Sugar_PHPUnit_Framework_TestCase
47 {
48     /**
49      * @var LayoutManager
50      */
51     protected $lm;
52
53     /**
54      * @var Currency
55      */
56     protected $currency_51568;
57
58     /**
59      * @var Currency
60      */
61     protected $currency_system;
62
63     /**
64      * @var string
65      */
66     protected $backupSymbol;
67
68     public function setUp()
69     {
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);
75
76         SugarTestHelper::setUp('app_list_strings');
77         SugarTestHelper::setUp('beanFiles');
78         SugarTestHelper::setUp('beanList');
79         parent::setUp();
80
81         $this->lm = new LayoutManager();
82         $this->lm->setAttribute('reporter', new stdClass());
83
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);
95     }
96
97     /**
98      * @group 51568
99      */
100     public function testFieldCurrencyPlainWithLayoutDef()
101     {
102         $data = array(
103             'currency_id' => $this->currency_51568->id,
104             'currency_symbol' => $this->currency_51568->symbol
105         );
106         $result = $this->getResults($data);
107         $this->assertEquals('TT100.500,000', $result);
108     }
109
110     /**
111      * @group 51568
112      */
113     public function testFieldCurrencyPlainWithCurrencyField()
114     {
115         $data = array(
116             'fields' => array(
117                 '51568table_some_field_currency' => $this->currency_51568->id)
118         );
119         $result = $this->getResults($data);
120         $this->assertEquals('TT100.500,000', $result);
121     }
122
123     /**
124      * @group 51568
125      */
126     public function testFieldCurrencyPlainWithAnotherCurrencyField()
127     {
128         $data = array(
129             'fields' => array(
130                 '51568TABLE_SOME_FIELD_CURRENCY' => $this->currency_51568->id)
131         );
132         $result = $this->getResults($data);
133         $this->assertEquals('TT100.500,000', $result);
134     }
135
136     /**
137      * @group 51568
138      */
139     public function testFieldCurrencyPlainWithSystemCurrencyField()
140     {
141         format_number(0, 0, 0, array(
142             'currency_id' => $this->currency_51568->id,
143             'currency_symbol' => $this->currency_51568->symbol
144         ));
145
146         format_number(0, 0, 0, array(
147             'currency_id' => -99,
148             'currency_symbol' => $this->currency_51568->getDefaultCurrencySymbol()
149         ));
150
151         $data = array(
152             'name' => 'some_field_usdoll',
153             'column_key' => 'self::some_field_usdoll',
154             'fields' => array(
155                 '51568TABLE_SOME_FIELD_USDOLL' => 100500
156             )
157         );
158         $result = $this->getResults($data);
159         $this->assertEquals('¥100.500,000', $result);
160     }
161
162     /**
163      * @group 51568
164      */
165     public function testFieldCurrencyPlainWithWrongCurrency()
166     {
167         $data = array(
168             'currency_id' => '-51568',
169             'currency_symbol' => '£'
170         );
171         $result = $this->getResults($data);
172         $this->assertEquals('¥100.500,000', $result);
173     }
174
175     protected function getResults($layout_def_addon)
176     {
177         $layout_def = array(
178             'column_key' => 'self::some_field',
179             'fields' => array(
180                 '51568TABLE_SOME_FIELD' => 100500,
181             ),
182             'name' => 'some_field',
183             'table_key' => 'self',
184             'table_alias' => '51568table',
185             'type' => 'currency'
186         );
187         foreach($layout_def_addon as $k => $v)
188         {
189             if(is_array($v))
190             {
191                 $layout_def = array_merge_recursive($layout_def, array($k => $v));
192             }
193             else
194             {
195                 $layout_def[$k] = $v;
196             }
197         }
198         $sf = $this->getMock('SugarWidgetFieldCurrency',
199             array('getTruncatedColumnAlias'),
200             array(&$this->lm));
201         $sf->expects($this->any())
202             ->method('getTruncatedColumnAlias')
203             ->will($this->returnArgument(0));
204         return $sf->displayListPlain($layout_def);
205     }
206
207     public function tearDown()
208     {
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;
213
214         format_number(0, 0, 0, array(
215             'currency_id' => $this->currency_51568->id,
216             'currency_symbol' => $this->currency_51568->symbol
217         ));
218
219         format_number(0, 0, 0, array(
220             'currency_id' => -99,
221             'currency_symbol' => $this->currency_51568->getDefaultCurrencySymbol()
222         ));
223
224         $this->currency_51568->mark_deleted($this->currency_51568->id);
225         SugarTestHelper::tearDown();
226         get_number_seperators(true);
227     }
228 }