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 ********************************************************************************/
38 require_once('include/SugarCharts/SugarChart.php');
41 * Bug 44696 - Wrong shortcut to the opportunities module from the dashlet
42 * "Pipeline By Sales Stage"
47 class Bug44696Test extends Sugar_PHPUnit_Framework_TestCase
52 protected $sugarChartObject;
56 protected $currentUser;
58 protected function setUp()
62 SugarTestHelper::init();
63 SugarTestHelper::setUp('current_user');
64 $this->currentUser = $GLOBALS['current_user'];
65 $this->currentUser->setPreference(
66 'default_number_grouping_seperator',
69 $this->currentUser->setPreference('default_decimal_seperator', ',');
71 $sugarChartObject = new SugarChart();
72 $sugarChartObject->group_by = array('sales_stage', 'user_name');
73 $sugarChartObject->data_set = $this->getDataSet();
74 $sugarChartObject->base_url = array(
75 'module' => 'Opportunities',
78 'searchFormTab' => 'advanced_search'
80 $sugarChartObject->url_params = array();
81 $sugarChartObject->is_currency = true;
83 $sugarChartObject->super_set = array(
90 $this->sugarChartObject = $sugarChartObject;
93 protected function tearDown()
95 SugarTestHelper::tearDown();
100 * We check, that groups with NULL value remain their order in subgroups tag
101 * and won't fall down under not null valued groups.
102 * This way we guarantee that links will be put correctly to each user in
103 * whole user list (will, max, etc.).
108 public function testCorrectXml()
110 $actual = $this->sugarChartObject->xmlDataGenericChart();
111 $expected = $this->compareXml();
112 $order = array("\r\n", "\n", "\r", "\t");
114 // remove all break lines and spaces and tabs
115 $expected = str_replace($order, $replace, $expected);
116 $actual = str_replace($order, $replace, $actual);
117 $this->assertEquals($expected, $actual);
120 protected function getDataSet()
124 'sales_stage' => 'Proposal/Price Quote',
125 'user_name' => 'max',
126 'assigned_user_id' => 'seed_max_id',
129 'key' => 'Proposal/Price Quote',
130 'value' => 'Proposal/Price Quote',
133 'sales_stage' => 'Proposal/Price Quote',
134 'user_name' => 'sally',
135 'assigned_user_id' => 'seed_sally_id',
138 'key' => 'Proposal/Price Quote',
139 'value' => 'Proposal/Price Quote',
145 * Expected XML from SugarChart after.
148 * The XML string that we expect to be returned by the chart.
150 protected function compareXml()
152 $dataSet = $this->getDataSet();
153 $max = $dataSet[0]['total'];
154 $sally = $dataSet[1]['total'];
155 $total = $max + $sally;
157 list($maxSubAmount, $maxSubAmountFormatted) = $this->getAmounts($max);
158 list($sallySubAmount, $sallySubAmountFormatted) = $this->getAmounts(
161 list($totalSubAmount, $totalSubAmountFormatted) = $this->getAmounts(
166 <title>Proposal/Price Quote</title>
167 <value>{$totalSubAmount}</value>
168 <label>{$totalSubAmountFormatted}</label>
169 <link>index.php?module=Opportunities&action=index&query=true&searchFormTab=advanced_search&sales_stage=Proposal%2FPrice+Quote</link>
175 <link>index.php?module=Opportunities&action=index&query=true&searchFormTab=advanced_search&sales_stage=Proposal%2FPrice+Quote</link>
179 <value>{$maxSubAmount}</value>
180 <label>{$maxSubAmountFormatted}</label>
181 <link>index.php?module=Opportunities&action=index&query=true&searchFormTab=advanced_search&sales_stage=Proposal%2FPrice+Quote&assigned_user_id[]=seed_max_id</link>
187 <link>index.php?module=Opportunities&action=index&query=true&searchFormTab=advanced_search&sales_stage=Proposal%2FPrice+Quote</link>
191 <value>{$sallySubAmount}</value>
192 <label>{$sallySubAmountFormatted}</label>
193 <link>index.php?module=Opportunities&action=index&query=true&searchFormTab=advanced_search&sales_stage=Proposal%2FPrice+Quote&assigned_user_id[]=seed_sally_id</link>
199 <link>index.php?module=Opportunities&action=index&query=true&searchFormTab=advanced_search&sales_stage=Proposal%2FPrice+Quote</link>
201 </subgroups></group>";
205 * Get the amounts that the chart should have for the value given.
207 * @param float $value
208 * The value to get formatted as chart would.
211 * A list with: the value in K's and the value in currency format.
213 protected function getAmounts($value)
216 global $sugar_config;
218 $subAmount = round($value, $locale->getPrecision($this->currentUser));
219 // TODO use the Localization::getLocaleFormattedNumber when it works!
220 // FIXME SugarCharts should use the user format preferences for charts
221 $subAmountFormatted = number_format(
223 $locale->getPrecision($this->currentUser),
224 $sugar_config['default_decimal_seperator'],
225 $sugar_config['default_number_grouping_seperator']
227 $subAmountFormatted = $locale->getCurrencySymbol(
229 ) . $subAmountFormatted . 'K';
231 return array($subAmount, $subAmountFormatted);