]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/generic/SugarWidgets/Bug51568Test.php
Release 6.5.8
[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-2012 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         $data = array(
142             'name' => 'some_field_usdoll',
143             'column_key' => 'self::some_field_usdoll',
144             'fields' => array(
145                 '51568TABLE_SOME_FIELD_USDOLL' => 100500
146             )
147         );
148         $result = $this->getResults($data);
149         $this->assertEquals('¥100.500,000', $result);
150     }
151
152     /**
153      * @group 51568
154      */
155     public function testFieldCurrencyPlainWithWrongCurrency()
156     {
157         $data = array(
158             'currency_id' => '-51568',
159             'currency_symbol' => '£'
160         );
161         $result = $this->getResults($data);
162         $this->assertEquals('¥100.500,000', $result);
163     }
164
165     protected function getResults($layout_def_addon)
166     {
167         $layout_def = array(
168             'column_key' => 'self::some_field',
169             'fields' => array(
170                 '51568TABLE_SOME_FIELD' => 100500,
171             ),
172             'name' => 'some_field',
173             'table_key' => 'self',
174             'table_alias' => '51568table',
175             'type' => 'currency'
176         );
177         foreach($layout_def_addon as $k => $v)
178         {
179             if(is_array($v))
180             {
181                 $layout_def = array_merge_recursive($layout_def, array($k => $v));
182             }
183             else
184             {
185                 $layout_def[$k] = $v;
186             }
187         }
188         $sf = $this->getMock('SugarWidgetFieldCurrency',
189             array('getTruncatedColumnAlias'),
190             array(&$this->lm));
191         $sf->expects($this->any())
192             ->method('getTruncatedColumnAlias')
193             ->will($this->returnArgument(0));
194         return $sf->displayListPlain($layout_def);
195     }
196
197     public function tearDown()
198     {
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);
206     }
207 }