All Data Structures Functions Variables Pages
DataToReportUtilTest.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo 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 ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo 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 Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified 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 Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
38  {
39  public static function setUpBeforeClass()
40  {
41  parent::setUpBeforeClass();
42  SecurityTestHelper::createSuperAdmin();
43  UserTestHelper::createBasicUser('bobby');
44  }
45 
46  public function setUp()
47  {
48  parent::setUp();
49  Yii::app()->user->userModel = User::getByUsername('super');
50  }
51 
52  public function testRowsAndColumnsResolveReportByWizardPostData()
53  {
54  $bobby = User::getByUserName('bobby');
55  $wizardFormClassName = 'RowsAndColumnsReportWizardForm';
56  $report = new Report();
57  $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
58  $data = array();
59  $data['moduleClassName'] = 'ReportsTestModule';
60  $data['description'] = 'a description';
61  $data['name'] = 'name';
62  $data['filtersStructure'] = '1 AND 2';
63  $data['ownerId'] = $bobby->id;
64  $data['currencyConversionType'] = Report::CURRENCY_CONVERSION_TYPE_SPOT;
65  $data['spotConversionCurrencyCode'] = 'EUR';
66  $data[ComponentForReportForm::TYPE_FILTERS][] = array('attributeIndexOrDerivedType' => 'date',
67  'valueType' => 'Between',
68  'value' => '2/24/2012',
69  'secondValue' => '2/28/2012');
70  $data[ComponentForReportForm::TYPE_ORDER_BYS][] = array('attributeIndexOrDerivedType' => 'string',
71  'order' => 'desc');
72  $data[ComponentForReportForm::TYPE_DISPLAY_ATTRIBUTES][] = array('attributeIndexOrDerivedType' => 'phone',
73  'label' => 'custom');
74  DataToReportUtil::resolveReportByWizardPostData($report, array('RowsAndColumnsReportWizardForm' => $data),
75  $wizardFormClassName);
76  $this->assertEquals('ReportsTestModule', $report->getModuleClassName());
77  $this->assertEquals('a description', $report->getDescription());
78  $this->assertEquals('name', $report->getName());
79  $this->assertEquals('1 AND 2', $report->getFiltersStructure());
80  $this->assertEquals($bobby->id, $report->getOwner()->id);
81  $this->assertEquals(Report::CURRENCY_CONVERSION_TYPE_SPOT, $report->getCurrencyConversionType());
82  $this->assertEquals('EUR', $report->getSpotConversionCurrencyCode());
83 
84  $filters = $report->getFilters();
85  $this->assertCount(1, $filters);
86  $this->assertEquals('date', $filters[0]->getAttributeIndexOrDerivedType());
87  $this->assertEquals('Between', $filters[0]->valueType);
88  $this->assertEquals('2012-02-24', $filters[0]->value);
89  $this->assertEquals('2012-02-28', $filters[0]->secondValue);
90  $orderBys = $report->getOrderBys();
91  $this->assertCount(1, $orderBys);
92  $this->assertEquals('string', $orderBys[0]->getAttributeIndexOrDerivedType());
93  $this->assertEquals('desc', $orderBys[0]->order);
94  $displayAttributes = $report->getDisplayAttributes();
95  $this->assertCount(1, $orderBys);
96  $this->assertEquals('phone', $displayAttributes[0]->getAttributeIndexOrDerivedType());
97  $this->assertEquals('custom', $displayAttributes[0]->label);
98  }
99 
100  public function testSummationResolveReportByWizardPostData()
101  {
102  $bobby = User::getByUserName('bobby');
103  $wizardFormClassName = 'SummationReportWizardForm';
104  $report = new Report();
105  $report->setType(Report::TYPE_SUMMATION);
106  $data = array();
107  $data['moduleClassName'] = 'ReportsTestModule';
108  $data['description'] = 'a description';
109  $data['name'] = 'name';
110  $data['filtersStructure'] = '1 AND 2';
111  $data['ownerId'] = $bobby->id;
112  $data['currencyConversionType'] = Report::CURRENCY_CONVERSION_TYPE_SPOT;
113  $data['spotConversionCurrencyCode'] = 'EUR';
114  $data[ComponentForReportForm::TYPE_FILTERS][] = array('attributeIndexOrDerivedType' => 'date',
115  'valueType' => 'Between',
116  'value' => '2/24/2012',
117  'secondValue' => '2/28/2012');
118  $data[ComponentForReportForm::TYPE_ORDER_BYS][] = array('attributeIndexOrDerivedType' => 'string',
119  'order' => 'desc');
120  $data[ComponentForReportForm::TYPE_DISPLAY_ATTRIBUTES][] = array('attributeIndexOrDerivedType' => 'phone',
121  'label' => 'custom');
123  array('attributeIndexOrDerivedType' => 'string',
124  'label' => 'custom string');
125  $data[ComponentForReportForm::TYPE_GROUP_BYS][] = array('attributeIndexOrDerivedType' => 'string',
126  'axis' => 'y');
127  $data['ChartForReportForm'] = array('type' => ChartRules::TYPE_BAR_2D,
128  'firstSeries' => 'string',
129  'firstRange' => 'integer__Maximum');
130  DataToReportUtil::resolveReportByWizardPostData($report, array('SummationReportWizardForm' => $data),
131  $wizardFormClassName);
132  $this->assertEquals('ReportsTestModule', $report->getModuleClassName());
133  $this->assertEquals('a description', $report->getDescription());
134  $this->assertEquals('name', $report->getName());
135  $this->assertEquals('1 AND 2', $report->getFiltersStructure());
136  $this->assertEquals($bobby->id, $report->getOwner()->id);
137  $this->assertEquals(Report::CURRENCY_CONVERSION_TYPE_SPOT, $report->getCurrencyConversionType());
138  $this->assertEquals('EUR', $report->getSpotConversionCurrencyCode());
139 
140  $filters = $report->getFilters();
141  $this->assertCount(1, $filters);
142  $this->assertEquals('date', $filters[0]->getAttributeIndexOrDerivedType());
143  $this->assertEquals('Between', $filters[0]->valueType);
144  $this->assertEquals('2012-02-24', $filters[0]->value);
145  $this->assertEquals('2012-02-28', $filters[0]->secondValue);
146  $orderBys = $report->getOrderBys();
147  $this->assertCount(1, $orderBys);
148  $this->assertEquals('string', $orderBys[0]->getAttributeIndexOrDerivedType());
149  $this->assertEquals('desc', $orderBys[0]->order);
150  $displayAttributes = $report->getDisplayAttributes();
151  $this->assertCount(1, $displayAttributes);
152  $this->assertEquals('phone', $displayAttributes[0]->getAttributeIndexOrDerivedType());
153  $this->assertEquals('custom', $displayAttributes[0]->label);
154  $groupBys = $report->getGroupBys();
155  $this->assertCount(1, $groupBys);
156  $this->assertEquals('string', $groupBys[0]->getAttributeIndexOrDerivedType());
157  $this->assertEquals('y', $groupBys[0]->axis);
158  $drillDownDisplayAttributes = $report->getDrillDownDisplayAttributes();
159  $this->assertCount(1, $drillDownDisplayAttributes);
160  $this->assertEquals('string', $drillDownDisplayAttributes[0]->getAttributeIndexOrDerivedType());
161  $this->assertEquals('custom string', $drillDownDisplayAttributes[0]->label);
162  $chart = $report->getChart();
163  $this->assertEquals(ChartRules::TYPE_BAR_2D, $chart->type);
164  $this->assertEquals('string', $chart->firstSeries);
165  $this->assertEquals('integer__Maximum', $chart->firstRange);
166  }
167 
168  public function testResolveFiltersAndDateConvertsProperlyToDbFormat()
169  {
170  $report = new Report();
171  $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
172  $report->setModuleClassName('ReportsTestModule');
173  $data = array();
174  $data[ComponentForReportForm::TYPE_FILTERS][] = array('attributeIndexOrDerivedType' => 'date',
175  'valueType' => 'Between',
176  'value' => '2/24/2012',
177  'secondValue' => '2/28/2012');
178  $data[ComponentForReportForm::TYPE_FILTERS][] = array('attributeIndexOrDerivedType' => 'dateTime',
179  'value' => '2/25/2012',
180  'availableAtRunTime' => true);
181  DataToReportUtil::resolveFilters($data, $report);
182  $filters = $report->getFilters();
183  $this->assertCount(2, $filters);
184  $this->assertEquals('Between', $filters[0]->valueType);
185  $this->assertEquals('2012-02-24', $filters[0]->value);
186  $this->assertEquals('2012-02-28', $filters[0]->secondValue);
187  $this->assertEquals('2012-02-25', $filters[1]->value);
188 
189  //Should remove only the runtime filter
190  $data = array();
191  $data[ComponentForReportForm::TYPE_FILTERS][] = array('attributeIndexOrDerivedType' => 'dateTime',
192  'value' => '2/25/2012',
193  'availableAtRunTime' => true);
194  DataToReportUtil::resolveFilters($data, $report, true);
195  $filters = $report->getFilters();
196  $this->assertCount(2, $filters);
197  $this->assertEquals('Between', $filters[0]->valueType);
198  $this->assertEquals('2012-02-24', $filters[0]->value);
199  $this->assertEquals('2012-02-28', $filters[0]->secondValue);
200  $this->assertEquals('2012-02-25', $filters[1]->value);
201  }
202 
203  public function testSanitizeFiltersData()
204  {
205  //test specifically for date/dateTime conversion from local to db format.
206  $filtersData = array();
207  $filtersData[0] = array('attributeIndexOrDerivedType' => 'date', 'value' => '2/24/2012');
208  $filtersData[1] = array('attributeIndexOrDerivedType' => 'dateTime', 'value' => '2/25/2012');
209  $filtersData[2] = array('attributeIndexOrDerivedType' => 'date', 'value' => '2/24/2012',
210  'secondValue' => '2/28/2012');
211  $sanitizedFilterData = DataToReportUtil::sanitizeFiltersData('ReportsTestModule',
212  Report::TYPE_ROWS_AND_COLUMNS, $filtersData);
213  $this->assertEquals('2012-02-24', $sanitizedFilterData[0]['value']);
214  $this->assertEquals('2012-02-25', $sanitizedFilterData[1]['value']);
215  $this->assertEquals('2012-02-24', $sanitizedFilterData[2]['value']);
216  $this->assertEquals('2012-02-28', $sanitizedFilterData[2]['secondValue']);
217  }
218  }
219 ?>
static resolveReportByWizardPostData(Report $report, $postData, $wizardFormClassName)
const CURRENCY_CONVERSION_TYPE_SPOT
Definition: Report.php:82
static getByUsername($username)
Definition: User.php:49
static sanitizeFiltersData($moduleClassName, $reportType, array $filtersData)
const TYPE_SUMMATION
Definition: Report.php:57
const TYPE_ROWS_AND_COLUMNS
Definition: Report.php:51
static resolveFilters($data, Report $report, $shouldRemoveOnlyRuntimeFilters=false)
Generated on Fri Jun 5 2020 07:10:34