2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2013 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/Jit/JitReports.php');
40 class Bug52901Test extends Sugar_PHPUnit_Framework_TestCase
42 public function setUp()
44 SugarTestHelper::setUp('current_user');
47 public function tearDown()
49 SugarTestHelper::tearDown();
54 * DataProvider function for test
58 public static function dataFeed()
62 // 1. type = '', industry = '';
63 // 2. type = 'Bar', industry = 'Foo'
64 'emptyTypeAndIndustry' => array(
70 'numerical_value' => 1,
72 'group_key' => 'self:account_type',
74 'group_label' => 'someHtml',
75 'numerical_label' => 'someHtml',
76 'numerical_key' => 'count',
77 'module' => 'Accounts',
78 'group_base_text' => '',
85 'numerical_value' => 1,
86 'group_text' => 'Bar',
87 'group_key' => 'self:account_type',
89 'group_label' => 'someHtml',
90 'numerical_label' => 'someHtml',
91 'numerical_key' => 'count',
92 'module' => 'Accounts',
93 'group_base_text' => 'Foo',
98 array('type', 'industry'),
99 array('', 'Foo', '', 'Foo'),
102 // 1. type = 'Foo', industry = 'Bar';
103 // 2. type = 'Bar', industry = 'Foo'
104 'bothDifferentTypeAndIndustry' => array(
110 'numerical_value' => 1,
111 'group_text' => 'Foo',
112 'group_key' => 'self:account_type',
114 'group_label' => 'someHtml',
115 'numerical_label' => 'someHtml',
116 'numerical_key' => 'count',
117 'module' => 'Accounts',
118 'group_base_text' => 'Bar',
125 'numerical_value' => 1,
126 'group_text' => 'Bar',
127 'group_key' => 'self:account_type',
129 'group_label' => 'someHtml',
130 'numerical_label' => 'someHtml',
131 'numerical_key' => 'count',
132 'module' => 'Accounts',
133 'group_base_text' => 'Foo',
138 array('type', 'industry'),
139 array('Foo', 'Bar', 'Foo', 'Bar'),
142 // 1. type = 'Foo', industry = 'Foo';
143 // 2. type = 'Bar', industry = 'Bar'
144 'bothEqualTypeAndIndustry' => array(
150 'numerical_value' => 1,
151 'group_text' => 'Bar',
152 'group_key' => 'self:account_type',
154 'group_label' => 'someHtml',
155 'numerical_label' => 'someHtml',
156 'numerical_key' => 'count',
157 'module' => 'Accounts',
158 'group_base_text' => 'Bar',
165 'numerical_value' => 1,
166 'group_text' => 'Foo',
167 'group_key' => 'self:account_type',
169 'group_label' => 'someHtml',
170 'numerical_label' => 'someHtml',
171 'numerical_key' => 'count',
172 'module' => 'Accounts',
173 'group_base_text' => 'Foo',
178 array('type', 'industry'),
179 array('Foo', 'Bar', 'Foo', 'Bar'),
181 // Accounts: Single group by. only by type
184 'onlyByType' => array(
190 'numerical_value' => 1,
191 'group_text' => 'Bar',
192 'group_key' => 'self:account_type',
194 'group_label' => 'someHtml',
195 'numerical_label' => 'someHtml',
196 'numerical_key' => 'count',
197 'module' => 'Accounts',
198 'group_base_text' => 'Bar',
205 'numerical_value' => 1,
206 'group_text' => 'Foo',
207 'group_key' => 'self:account_type',
209 'group_label' => 'someHtml',
210 'numerical_label' => 'someHtml',
211 'numerical_key' => 'count',
212 'module' => 'Accounts',
213 'group_base_text' => 'Foo',
227 * Test that <subgroups> is filled properly
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>
234 * @dataProvider dataFeed
237 public function testXMLIsGeneratedProperly($dataSet, $superSet, $groupBy, $expectedSubgroupNodesTitles)
239 $JR = new JitReports();
240 $JR->setData($dataSet);
241 $JR->super_set = $superSet;
242 $JR->setDisplayProperty('thousands', false);
243 $JR->group_by = $groupBy;
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>';
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)
256 $actualSubgroupNodesTitlesArray[] = $node->nodeValue;
259 $this->assertEquals($expectedSubgroupNodesTitles, $actualSubgroupNodesTitlesArray);