]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/SugarCharts/Bug52901Test.php
Release 6.5.10
[Github/sugarcrm.git] / tests / include / SugarCharts / Bug52901Test.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
38 require_once('include/SugarCharts/Jit/JitReports.php');
39
40 class Bug52901Test extends Sugar_PHPUnit_Framework_TestCase
41 {
42     public function setUp()
43     {
44         SugarTestHelper::setUp('current_user');
45     }
46
47     public function tearDown()
48     {
49         SugarTestHelper::tearDown();
50     }
51
52
53     /**
54      * DataProvider function for test
55      * @static
56      * @return array
57      */
58     public static function dataFeed()
59     {
60         $dataSeed = array(
61             // Accounts:
62             // 1. type = '', industry = '';
63             // 2. type = 'Bar', industry = 'Foo'
64             'emptyTypeAndIndustry' => array(
65                 array(
66                     '' =>
67                     array(
68                         '' =>
69                         array(
70                             'numerical_value' => 1,
71                             'group_text' => '',
72                             'group_key' => 'self:account_type',
73                             'count' => '',
74                             'group_label' => 'someHtml',
75                             'numerical_label' => 'someHtml',
76                             'numerical_key' => 'count',
77                             'module' => 'Accounts',
78                             'group_base_text' => '',
79                         ),
80                     ),
81                     'Bar' =>
82                     array(
83                         'Foo' =>
84                         array(
85                             'numerical_value' => 1,
86                             'group_text' => 'Bar',
87                             'group_key' => 'self:account_type',
88                             'count' => '',
89                             'group_label' => 'someHtml',
90                             'numerical_label' => 'someHtml',
91                             'numerical_key' => 'count',
92                             'module' => 'Accounts',
93                             'group_base_text' => 'Foo',
94                         ),
95                     ),
96                 ),
97                 array('', 'Foo'),
98                 array('type', 'industry'),
99                 array('', 'Foo', '', 'Foo'),
100             ),
101             // Accounts:
102             // 1. type = 'Foo', industry = 'Bar';
103             // 2. type = 'Bar', industry = 'Foo'
104             'bothDifferentTypeAndIndustry' => array(
105                 array(
106                     'Foo' =>
107                     array(
108                         'Bar' =>
109                         array(
110                             'numerical_value' => 1,
111                             'group_text' => 'Foo',
112                             'group_key' => 'self:account_type',
113                             'count' => '',
114                             'group_label' => 'someHtml',
115                             'numerical_label' => 'someHtml',
116                             'numerical_key' => 'count',
117                             'module' => 'Accounts',
118                             'group_base_text' => 'Bar',
119                         ),
120                     ),
121                     'Bar' =>
122                     array(
123                         'Foo' =>
124                         array(
125                             'numerical_value' => 1,
126                             'group_text' => 'Bar',
127                             'group_key' => 'self:account_type',
128                             'count' => '',
129                             'group_label' => 'someHtml',
130                             'numerical_label' => 'someHtml',
131                             'numerical_key' => 'count',
132                             'module' => 'Accounts',
133                             'group_base_text' => 'Foo',
134                         ),
135                     ),
136                 ),
137                 array('Foo', 'Bar'),
138                 array('type', 'industry'),
139                 array('Foo', 'Bar', 'Foo', 'Bar'),
140             ),
141             // Accounts:
142             // 1. type = 'Foo', industry = 'Foo';
143             // 2. type = 'Bar', industry = 'Bar'
144             'bothEqualTypeAndIndustry' => array(
145                 array(
146                     'Bar' =>
147                     array(
148                         'Bar' =>
149                         array(
150                             'numerical_value' => 1,
151                             'group_text' => 'Bar',
152                             'group_key' => 'self:account_type',
153                             'count' => '',
154                             'group_label' => 'someHtml',
155                             'numerical_label' => 'someHtml',
156                             'numerical_key' => 'count',
157                             'module' => 'Accounts',
158                             'group_base_text' => 'Bar',
159                         ),
160                     ),
161                     'Foo' =>
162                     array(
163                         'Foo' =>
164                         array(
165                             'numerical_value' => 1,
166                             'group_text' => 'Foo',
167                             'group_key' => 'self:account_type',
168                             'count' => '',
169                             'group_label' => 'someHtml',
170                             'numerical_label' => 'someHtml',
171                             'numerical_key' => 'count',
172                             'module' => 'Accounts',
173                             'group_base_text' => 'Foo',
174                         ),
175                     ),
176                 ),
177                 array('Foo', 'Bar'),
178                 array('type', 'industry'),
179                 array('Foo', 'Bar', 'Foo', 'Bar'),
180             ),
181             // Accounts: Single group by. only by type
182             // 1. type = 'Foo'
183             // 2. type = 'Bar'
184             'onlyByType' => array(
185                 array(
186                     'Bar' =>
187                     array(
188                         'Bar' =>
189                         array(
190                             'numerical_value' => 1,
191                             'group_text' => 'Bar',
192                             'group_key' => 'self:account_type',
193                             'count' => '',
194                             'group_label' => 'someHtml',
195                             'numerical_label' => 'someHtml',
196                             'numerical_key' => 'count',
197                             'module' => 'Accounts',
198                             'group_base_text' => 'Bar',
199                         ),
200                     ),
201                     'Foo' =>
202                     array(
203                         'Foo' =>
204                         array(
205                             'numerical_value' => 1,
206                             'group_text' => 'Foo',
207                             'group_key' => 'self:account_type',
208                             'count' => '',
209                             'group_label' => 'someHtml',
210                             'numerical_label' => 'someHtml',
211                             'numerical_key' => 'count',
212                             'module' => 'Accounts',
213                             'group_base_text' => 'Foo',
214                         ),
215                     ),
216                 ),
217                 array('Foo', 'Bar'),
218                 array('type'),
219                 array(),
220             ),
221         );
222
223         return $dataSeed;
224     }
225
226     /**
227      * Test that <subgroups> is filled properly
228      *
229      * @param $dataSet  array dataSet for JitReports
230      * @param $superSet array super_set for JitReports
231      * @param $groupBy array array of group_by levels
232      * @param $expectedSubgroupNodesTitles array expected list of values of node <title> in each node <subgroups>
233      *
234      * @dataProvider dataFeed
235      * @group 52901
236      */
237     public function testXMLIsGeneratedProperly($dataSet, $superSet, $groupBy, $expectedSubgroupNodesTitles)
238     {
239         $JR = new JitReports();
240         $JR->setData($dataSet);
241         $JR->super_set = $superSet;
242         $JR->setDisplayProperty('thousands', false);
243         $JR->group_by = $groupBy;
244
245         // We do this because the function which is under the test (xmlDataReportChart()) returns XML without root node and thus causes XML parse error
246         $actualXML = '<data>' . $JR->xmlDataReportChart() . '</data>';
247
248         // Get the list of <title> node value elements of each <subgroup>
249         $dom = new DomDocument();
250         $dom->loadXML($actualXML);
251         $xpath = new DomXPath($dom);
252         $nodes = $xpath->query('group/subgroups/group/title');
253         $actualSubgroupNodesTitlesArray = array();
254         foreach ($nodes as $node)
255         {
256             $actualSubgroupNodesTitlesArray[] = $node->nodeValue;
257         }
258
259         $this->assertEquals($expectedSubgroupNodesTitles, $actualSubgroupNodesTitlesArray);
260     }
261
262 }