]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/SugarCharts/Bug44696Test.php
Release 6.4.1
[Github/sugarcrm.git] / tests / include / SugarCharts / Bug44696Test.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/SugarCharts/SugarChart.php');
38 /**
39  * Created: Sep 28, 2011
40  */
41 class Bug44696Test extends Sugar_PHPUnit_Framework_TestCase
42 {
43     public $sugarChartObject;
44     
45     public function setUp()
46     {
47         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
48         $sugarChartObject = new SugarChart();
49         $sugarChartObject->group_by = array ('sales_stage', 'user_name');
50         $sugarChartObject->data_set = $this->getDataSet();
51         $sugarChartObject->base_url = array ('module' => 'Opportunities',
52                                                                                 'action' => 'index',
53                                                                                 'query' => 'true',
54                                                                                 'searchFormTab' => 'advanced_search');
55         $sugarChartObject->url_params = array ();
56         $sugarChartObject->is_currency = true;
57         // we have 5 users 
58         $sugarChartObject->super_set = array ('will', 'max', 'sarah', 'sally', 'chris');
59         $this->sugarChartObject = $sugarChartObject;
60     }
61
62     public function tearDown()
63     {
64         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
65         unset($GLOBALS['current_user']);
66     }
67     
68     public function getDataSet() {
69         return array (
70            array (
71                 'sales_stage' => 'Proposal/Price Quote',
72                'user_name' => 'max',
73                'assigned_user_id' => 'seed_max_id',
74                'opp_count' => '1',
75                'total' => '50',
76                'key' => 'Proposal/Price Quote',
77                'value' => 'Proposal/Price Quote',
78                ), 
79             array (
80                 'sales_stage' => 'Proposal/Price Quote',
81                'user_name' => 'sally',
82                'assigned_user_id' => 'seed_sally_id',
83                'opp_count' => '2',
84                'total' => '75',
85                'key' => 'Proposal/Price Quote',
86                'value' => 'Proposal/Price Quote',
87                ),
88         );
89     }
90     
91     /**
92      * We check, that groups with NULL value remain their order in subgroups tag and won't fall down under not null valued groups. 
93      * This way we guarantee that links will be put correctly to each user in whole user list (will, max, etc.). 
94      */
95     public function testCorrectXml() 
96     {
97         $actual = $this->sugarChartObject->xmlDataGenericChart();
98         $expected = $this->compareXml();
99         $order   = array("\r\n", "\n", "\r", "\t");
100         $replace = "";
101         // remove all break lines and spaces and tabs
102             $expected = str_replace($order, $replace, $expected);
103             $actual = str_replace($order, $replace, $actual);
104         $this->assertEquals($expected, $actual);
105     }
106     
107     /**
108      * @return xml string  
109      */
110     public function compareXml() 
111     {
112         $max = 50;
113         $sally = 75;
114         $total = $max + $sally;
115         $max = $this->convertCurrency($max);
116         $sally = $this->convertCurrency($sally);
117         $total = $this->convertCurrency($total);
118         
119         return "<group>
120                         <title>Proposal/Price Quote</title>
121                         <value>{$total->subAmount}</value>
122                         <label>{$total->subAmountFormatted}</label>
123                         <link>index.php?module=Opportunities&action=index&query=true&searchFormTab=advanced_search&sales_stage=Proposal%2FPrice+Quote</link>
124                         <subgroups>
125                                 <group>
126                                         <title>will</title>
127                                         <value>NULL</value>
128                                         <label></label>
129                                         <link>index.php?module=Opportunities&action=index&query=true&searchFormTab=advanced_search&sales_stage=Proposal%2FPrice+Quote</link>
130                                 </group>
131                                 <group>
132                                         <title>max</title>
133                                         <value>{$max->subAmount}</value>
134                                         <label>{$max->subAmountFormatted}</label>
135                                         <link>index.php?module=Opportunities&action=index&query=true&searchFormTab=advanced_search&sales_stage=Proposal%2FPrice+Quote&assigned_user_id[]=seed_max_id</link>
136                                 </group>
137                                 <group>
138                                         <title>sarah</title>
139                                         <value>NULL</value>
140                                         <label></label>
141                                         <link>index.php?module=Opportunities&action=index&query=true&searchFormTab=advanced_search&sales_stage=Proposal%2FPrice+Quote</link>
142                                 </group>
143                                 <group>
144                                         <title>sally</title>
145                                         <value>{$sally->subAmount}</value>
146                                         <label>{$sally->subAmountFormatted}</label>
147                                         <link>index.php?module=Opportunities&action=index&query=true&searchFormTab=advanced_search&sales_stage=Proposal%2FPrice+Quote&assigned_user_id[]=seed_sally_id</link>
148                                 </group>
149                                 <group>
150                                         <title>chris</title>
151                                         <value>NULL</value>
152                                         <label></label>
153                                         <link>index.php?module=Opportunities&action=index&query=true&searchFormTab=advanced_search&sales_stage=Proposal%2FPrice+Quote</link>
154                                 </group>
155                         </subgroups></group>";
156     }
157     
158     public function convertCurrency($value) {
159         $sub_amount = $this->sugarChartObject->formatNumber($this->sugarChartObject->convertCurrency($value));
160         $sub_amount_formatted = $this->sugarChartObject->currency_symbol . $sub_amount . 'K';
161         $sub_amount = $this->sugarChartObject->convertCurrency($value);
162         $return = new stdClass();
163         $return->subAmount = $sub_amount;
164         $return->subAmountFormatted = $sub_amount_formatted;
165         return $return;
166     }
167 }